Prompt for save onunload unless...

Posted on 2006-04-18
Last Modified: 2006-11-18

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:


function rtFalse(){
if(confirm('Save data?')){document.forms['myForm'].submit();}

Question by:Bonnie_K
    LVL 9

    Accepted Solution

    isFromLink = false;
    function rtFalse(){
    if (!isFromLink ) {
    if(confirm('Save data?')){document.forms['myForm'].submit();}}

    And in your link:

    <a href="" onclick="isFromLink = true;">Load Address</a>

    Author Comment

    Thanks! Works perfectly.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Specialist

    HTML5 development skills are critical to all developers. HTML5 is the foundation to almost any development process. That's why business, design studios, development shops and other organizations need HTML5 developers. Get your foot in the door as a HTML5 specialist.

    A common challenge, or question, when working with two calendar dates is: What is the difference between the specified days? As is frequently the case, the answer is: It depends... What kind of difference do you want? Given two date obje…
    This article shows how to read a single webpage's HTML into a string variable, and it also shows how to automate a sequence so you can read and process a list of webpages.  I was tasked with reading and parsing a series of webpages to collect some s…
    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…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now