Link to home
Start Free TrialLog in
Avatar of Bonnie_K
Bonnie_K

asked on

Prompt for save onunload unless...

Hello,

I want users to be prompted for save onunload unless they click a certain link called Load Address.  

The code below works perfectly for prompting the user when they close or leave the page.

I thought I could set a variable onload in the body tag and then condition the confirm prompt on the value of the variable.  I would then change the variable's value if they clicked the Load Address link and then they would not be prompted.  My idea doesn't work at all.  

Any ideas?

I got this code from a post by hensen in Q_20451277:

<script>

window.onunload=rtFalse;
function rtFalse(){
if(confirm('Save data?')){document.forms['myForm'].submit();}
}
</script>


Thanks,
Bonnie
ASKER CERTIFIED SOLUTION
Avatar of smaccari
smaccari

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bonnie_K
Bonnie_K

ASKER

Thanks! Works perfectly.