| | |
Warning Message on Browser Close
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi,
Even I am trying the browser close event for cross browser and this should trigger only when X button is clicked or page is refreshed. Here's the code pasted above which I am using but it only works in IE.
I know the issue is because of window.events and ClientX/ClientY.
Could someone please fix my code to make it work in all browsers? This is very urgent and have been striving since 3 days...
*Please Note: Current code is working in IE only and to check you have to close the browser window or refresh the page with mouse click
Even I am trying the browser close event for cross browser and this should trigger only when X button is clicked or page is refreshed. Here's the code pasted above which I am using but it only works in IE.
I know the issue is because of window.events and ClientX/ClientY.
Could someone please fix my code to make it work in all browsers? This is very urgent and have been striving since 3 days...
*Please Note: Current code is working in IE only and to check you have to close the browser window or refresh the page with mouse click
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
===================== <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><head> <title>Warning Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script language="JavaScript"> // warning message javascript var isOpera, isIE, isNav, isFox, isOther = false; if (navigator.userAgent.indexOf("Opera") != -1) { isOpera = true; } else if (navigator.userAgent.indexOf("Firefox") != -1) { isFox = true; } else if (navigator.appName == "Microsoft Internet Explorer") { isIE = true; } else if (navigator.appName == "Netscape") { isNav = true; } else { isOther = true; } if (isIE || isOpera || isNav || isFox || isOther) { window.onbeforeunload = WarnUser; function WarnUser() { OffsetX = window.event.clientX; OffsetY = window.event.clientY; if (((window.event.clientX < 0) || (window.event.clientY < 0)) && (isWarnUser == true)) { event.returnValue = " "; //window. önunload = sessionInvalidate; } else { // Reset the flag to its default value. isWarnUser = true; } } } </script> </head> <body> <script type="text/javascript"> var isWarnUser = true; </script> test </body> </html> ========================
•
•
Join Date: Oct 2009
Posts: 17
Reputation:
Solved Threads: 2
0
#2 23 Days Ago
•
•
•
•
Hi,
Even I am trying the browser close event for cross browser and this should trigger only when X button is clicked or page is refreshed. Here's the code pasted above which I am using but it only works in IE.
I know the issue is because of window.events and ClientX/ClientY.
Could someone please fix my code to make it work in all browsers? This is very urgent and have been striving since 3 days...
*Please Note: Current code is working in IE only and to check you have to close the browser window or refresh the page with mouse clickJavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
===================== <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><head> <title>Warning Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script language="JavaScript"> // warning message javascript var isOpera, isIE, isNav, isFox, isOther = false; if (navigator.userAgent.indexOf("Opera") != -1) { isOpera = true; } else if (navigator.userAgent.indexOf("Firefox") != -1) { isFox = true; } else if (navigator.appName == "Microsoft Internet Explorer") { isIE = true; } else if (navigator.appName == "Netscape") { isNav = true; } else { isOther = true; } if (isIE || isOpera || isNav || isFox || isOther) { window.onbeforeunload = WarnUser; function WarnUser() { OffsetX = window.event.clientX; OffsetY = window.event.clientY; if (((window.event.clientX < 0) || (window.event.clientY < 0)) && (isWarnUser == true)) { event.returnValue = " "; //window. önunload = sessionInvalidate; } else { // Reset the flag to its default value. isWarnUser = true; } } } </script> </head> <body> <script type="text/javascript"> var isWarnUser = true; </script> test </body> </html> ========================
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<BODY onUnload="function()">
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.onkeydown=keyaction; function keyaction(e) { if(!e)e = window.event; alert(e.keyCode); switch(e.keyCode) { case 63:function() } }
if you want to occur only if the X or refresh button is press, i don;t know how to do that...
another thing that you should know is that such a event when you are closing the window/site is annoying sometimes, at least the one you put in the test
0
#3 23 Days Ago
•
•
•
•
ok, first of all i am not really sure what you want to do, but there is a event that occurs when you close the window.. and that is:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<BODY onUnload="function()">
•
•
•
•
if you want to check if the F5 button on the keyboard is pressed try something like:
i don;t remember what is the code for F5, try that code and check it out...JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.onkeydown=keyaction; function keyaction(e) { if(!e)e = window.event; alert(e.keyCode); switch(e.keyCode) { case 63:function() } }
if you want to occur only if the X or refresh button is press, i don;t know how to do that...
another thing that you should know is that such a event when you are closing the window/site is annoying sometimes, at least the one you put in the test
Here's what I'dd do:
JavaScript Syntax (Toggle Plain Text)
<html> <head> <script language="javascript"> var isWarnUser = false; function on_unload() { if(isWarnUser) return " "; isWarnUser = true; } </script> </head> <body onbeforeunload="return on_unload();">.....</body> </html>
Last edited by Alxandr; 23 Days Ago at 6:58 pm.
•
•
Join Date: Nov 2009
Posts: 3
Reputation:
Solved Threads: 0
0
#4 22 Days Ago
•
•
•
•
Actually, this is not correct. There might bee a event named onunload (small-case is proffered after my knowledge), but the event onbeforeunload is triggered before that (I don't know the difference though, but my guessing is that onbeforeunload is triggered before the DOM-model is destroyed). Not saying that onunload is wrong, but it's not the only event triggered at browser close|redirect|refresh|++ At work we use onbeforeunload to save changes and it's confirmed working in all the browsers (though it's an ugly hack).
This might be true, it might be called when F5 is pressed, but I think this is browser-based, though not sure about that. Though what I do know is that handling onbeforeunload is somewhat difficult.
Here's what I'dd do:
JavaScript Syntax (Toggle Plain Text)
<html> <head> <script language="javascript"> var isWarnUser = false; function on_unload() { if(isWarnUser) return " "; isWarnUser = true; } </script> </head> <body onbeforeunload="return on_unload();">.....</body> </html>
Nothing works out, please have a double check before delivering code.
Best,
Ay
![]() |
Similar Threads
- Warning message? & NEXT page of ´results' not showing any results? (PHP)
- Warning Message (C++)
- Error message every time i close my internet explorer window (Web Browsers)
- Script Warning Message (Web Browsers)
- Browser close when screen saver close (Visual Basic 4 / 5 / 6)
- warning message (C++)
- Word 2003 - warning message skipping (Windows Software)
- Hotoffers get me mad !! (Viruses, Spyware and other Nasties)
- Christopher_NG: IE6 Browser Window closes (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: How to Password protect files / sections on web page ?
- Next Thread: how can i make a window close itself after running the php code
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child class close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security shopping size software toggle unicode w3c web wysiwyg \n





