| | |
Warning Message on Browser Close
Please support our JavaScript / DHTML / AJAX advertiser: $6.99 Domain Names at 1&1. Includes Free Privacy. Save Now!
![]() |
•
•
Join Date: Nov 2009
Posts: 4
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 Nov 4th, 2009
•
•
•
•
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 Nov 4th, 2009
•
•
•
•
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; Nov 4th, 2009 at 5:58 pm.
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
0
#4 Nov 5th, 2009
•
•
•
•
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
Views: 952 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp ajaxjspservlets animate array boarder body box browser bug calling captcha checkbox child class content cookies countdown createrange() css cursor design div dom dynamic eclipse element error event exception explorer file firefox flash focus font form function google hide html iframe image images internet internet-explorer internetexplorer java javascript javascripts jquery js jsp jump library maps margin marquee modal mysql onclick onmouseover opacity parameters parent passing password perl php player plugins position post rating referenceerror refresh resize script scroll search select servlet session shopping show size starrating stretch strings text textarea validate values variables web window wysiwyg xhtml xml





