[RESOLVED]using javascript in onbeforeunload event


I want to warn a user if  the web page is closed accidentally without saving the data.  I am testing some javascript that would let the user know if the page is closed,

after checking the values of the checkboxes, and other elements on the page.   I only want this warning to apply to one page, and the application is using master pages.

I placed the javascript in the content area of the page I want this to run in and want to call it on the window.onbeforeunload  only if the javascript code has detected the user entered some values or checked off boxes..  When I close my browser, I never
execute the javascript code.  After the script tag, I have this:

windows.onbeforeunload=confirmexit();   But, it doesn’t get called.  I know this should work, but I don’t see what I’m doing wrong.

- I replaced the code with something simpler and now it works, so I think I had some syntax errors I must not have seen – thanks.

Hi maggiemays,

Use the following line of code, works well, and creates the alert box on its own.

window.onbeforeunload = function () {  return false; }

Hope this helps.

Leave a Reply