Hello,

I want to ask user about leaving page when there is some not saved data on page.
I wrote code

<script>
window.onbeforeunload= function() { return "Save your data plz"; };
</script>

But the problem is when am submitting data,
then am rendering another page.
Due to this confirm message, page is asking me to leave page after submission also.

How can I restrict that?

Recommended Answers

All 3 Replies

set javascript global variable onload
that warn=1;

but in onsubmit set warn= 0;

Then on unload, you can see variable value and put alert

<script>
window.onbeforeunload= function() { 
if (warn==1 ) return "Save your data plz"; };
</script>

Hello ,

Am using Yii.
So am doing submit function in controllers.
:(

so where you put the code you shown in your fist post?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.