tags:

views:

44

answers:

1

Hi there,

I have a page with a flash plugin. If I'm on that page, I don't want to post a message if the user wont to leaf it without saving it...:

if(/containers/.test(document.location.href)){
    window.onbeforeunload = function(){
      return exit_text;  
    };
}

This works fine, except that I if i save the content in the flash plugin. In that case I don't want to show up that message. How can I detect the url within the onbeforeunload method? That way I can descide when to post the method!

Thanks Markus

A: 

Only return a value in your onbeforeunload function if you want the prompt to show up:

window.onbeforeunload = function() {
    if(/containers/.test(document.location.href)
        return exit_test;
}

If you want to check the destination URL you are out of luck. However, you can still set a variable when the user clicks the link which will got to that URL and then check on that variable.

ThiefMaster
that doesn't work, because document.location.href is the actual page name and not the one, witch it will be redirected to.
Markus