Page 1 of 1

Working With window.onbeforeunload

Posted: Tue May 20, 2008 8:34 am
by icesolid
I have a page that I have used the window.onbeforeunload code on. My only problem is that there is a "enlarge a photo" function used on the page that opens a little pop-up to blow up a photo. The window.onbeforeunload function works great however it wont let the pop-up window through. How can I make an exception for that enlarge() function, pop up window?

Here is what I am trying to do:

Code: Select all

if(windows is unloaded) {
    if(enlarge photo function was clicked) {
        do NOT display the "are you sure you want to navigate away" dialog box.
    } else {
         do display the "are you sure you want to navigate away" dialog box.
    }
} 

Re: Working With window.onbeforeunload

Posted: Tue May 20, 2008 7:52 pm
by Jonah Bron
How about this?

Code: Select all

var isPopup = false;
window.onbeforeunload = function (){
    if (isPopup){
        // don't do whatever it does
    }else{
        // do the thing, because it's not the popup opening
    }
}
function openPopup(){
    isPopup = true;
    window.open(/* ... */);
}