Feivi99
asked on
window.onbeforeunload url exception
Hi everyone,
I have a page which shows a confirm message when the user tries to leave it, using window.onbeforeunload.
Now I only want it to fire if the url the user is going to is not on my domain. i.e. he'll only get it when trying to close the tab/window or surfing to a different website, but not when reloading my page.
TIA!
I have a page which shows a confirm message when the user tries to leave it, using window.onbeforeunload.
Now I only want it to fire if the url the user is going to is not on my domain. i.e. he'll only get it when trying to close the tab/window or surfing to a different website, but not when reloading my page.
TIA!
ASKER
wht, that worked pretty nicely. The only thing that's missing for me is to keep it from happening when the user clicks the browser's "reload" button. Any way you can think of doing that?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Feivi99,
since that worked ok for you above, could you accept the solution please. Thanks - KW
since that worked ok for you above, could you accept the solution please. Thanks - KW
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var isOkToLeave = false;
function MyBeforeUnloadEvent()
{
if (!isOkToLeave )
return confirm('do you really want to leave?');
}
then in all your code for every button or hyperlink have some client event that sets this to true.
<asp:Button .... OnClientClick="isOkToLeave
This way you are telling the onbeforeclose event that it is ok to leave, otherwise hitting the back button on the browser, typing a new URL, etc, will cause the confirm dialog to be presented