Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is "Are you sure you want to navigate away from this page? " generated in browsers?

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.

like image 492
Gabriel Avatar asked Oct 15 '22 17:10

Gabriel


1 Answers

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.

like image 145
DanSingerman Avatar answered Oct 18 '22 09:10

DanSingerman