?
Solved

Prompt for save onunload unless...

Posted on 2006-04-18
2
Medium Priority
?
180 Views
Last Modified: 2006-11-18
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
0
Comment
Question by:Bonnie_K
2 Comments
 
LVL 9

Accepted Solution

by:
smaccari earned 2000 total points
ID: 16478712
<script>
isFromLink = false;
window.onunload=rtFalse;
function rtFalse(){
if (!isFromLink ) {
if(confirm('Save data?')){document.forms['myForm'].submit();}}
}
</script>

And in your link:

<a href="http://www.google.fr" onclick="isFromLink = true;">Load Address</a>
0
 

Author Comment

by:Bonnie_K
ID: 16488615
Thanks! Works perfectly.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question