views:

3402

answers:

4

I have a page where I open a "modal window". It is really just a DIV, with an IFRAME inside, where I load another page. When I want to refresh the page, the browser pops up a window saying "Are you sure you want to navigate away from this page? Reloading this page will cause the modal window to disappear. Press OK to continue, or Cancel to stay on the current page."

How does this message get generated? How does the browser figure out that I have a modal window there, because I don't use any window.open() call from JavaScript? Is there any way to disable this behavior of the browser.

+2  A: 

It may be body.onunload in the source of the page loaded in the IFRAME.

As the modal window is essentially an IFRAME, then when you close (or refresh) the main window, the browser knows it is killing that IFRAME, hence any body.onunload in that IFRAME fires.

DanSingerman
You're right. Actually I am working with the Wicket framework and I searched in their source code, and look what I found:window.onbeforeunload = function() { return "Reloading this page will cause the modal window to disappear.";} Fortunately this can be disabled easily. Thanks!
Gabi
A: 

This could be caused by some script modifying all off-site links to display this modal window, and then return true, or return false based upon your interaction with the modal window.

If you want to strip that behavior, you could remove all click events for external links.

Jonathan Sampson
A: 

Can you please indicate with little more detail how to disable this alert behavior? Thanks. I still need to figure how not to trigger the popup alert window.

A: 

Hi,

If you have a function that handel onbeforeunload, automaticaly the Firefox message is generated.

you can disable it by returning null at the and of your handler.

ilham