Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Sign In| Join
Last post May 19, 2009 08:38 AM by vinz
Member
56 Points
306 Posts
May 19, 2009 07:11 AM|LINK
I wantto fire some event when user clicks (X) of the aspx page. Which event of the page should i use. I guesss it is not Page_Unload event.
thanks in advance....
How to fire some event after closing the page from(X)
All-Star
32477 Points
6738 Posts
May 19, 2009 08:01 AM|LINK
kem06.net I wantto fire some event when user clicks (X) of the aspx page. Which event of the page should i use. I guesss it is not Page_Unload event. thanks in advance....
I think you have to call javascript onbeforeUnload
Star
12114 Points
2139 Posts
May 19, 2009 08:19 AM|LINK
Try this:
<html> <body onbeforeunload="if(!Navigating){ alert('Browser close attempt is detected');return 'Browser close attempt
is detected'}else{Navigating=false;}"> <!-- Unimportant Sample Links & Forms to test all kinds of them, with/without event handlers... --> <a href="http://www.google.com/">Navigate Away 1 (No Event Handler)</a><br> <a href="http://www.google.com/" onclick="alert('Link Event Handler 1');">Navigate Away 2 (Event Handler 1)</a><br> <a href="http://www.google.com/" id="link">Navigate Away 3 (Event Handler 2)</a><br> <script language="javascript"> document.getElementById('link').onclick=function(){ alert('Link Event Handler 2'); }; </script> <form action="http://www.google.com/"> <input type="submit" value="Navigate Away 1 (No Event Handler)"> </form> <form action="http://www.google.com/" onsubmit="alert('Form Event Handler');"> <input type="submit" value="Navigate Away 2 (Event Handler)"> </form> <!-- End of Unimportant Samples! --> <script language="javascript"> var Navigating=false; function ChargeHandler(obj,eve){ obj.oldHandler=obj[eve]; obj[eve]=function(){ if(obj.oldHandler!=null) obj.oldHandler(); Navigating=true; }; } //Add Navigating=true; to all links.onclick & all forms.onsubmit event handlers... for(i=0;i<document.links.length;i++) ChargeHandler(document.links[i],'onclick'); for(i=0;i<document.forms.length;i++) ChargeHandler(document.forms[i],'onsubmit'); </script> </body> </html>
Reference: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23748383.html
389 Points
85 Posts
May 19, 2009 08:36 AM|LINK
Hello,
You can use onbeforeunload event for this like:
<body onbeforeunload="alert('Closing');">
Thanks
116098 Points
16314 Posts
MVP
May 19, 2009 08:38 AM|LINK
kem06.net I wantto fire some event when user clicks (X) of the aspx page. Which event of the page should i use.
AFAIK,the only events that you can use when the browser is closed is the onunload or the onbeforeunload event. Look here for more information. http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
You may also use Page Methods as demonstrated in the link below:
kem06.net
Member
56 Points
306 Posts
How to fire some event after closing the page from(X)
May 19, 2009 07:11 AM|LINK
I wantto fire some event when user clicks (X) of the aspx page. Which event of the page should i use. I guesss it is not Page_Unload event.
thanks in advance....
How to fire some event after closing the page from(X)
venkatu2005
All-Star
32477 Points
6738 Posts
Re: How to fire some event after closing the page from(X)
May 19, 2009 08:01 AM|LINK
I think you have to call javascript onbeforeUnload
Thanks.
sumitd
Star
12114 Points
2139 Posts
Re: How to fire some event after closing the page from(X)
May 19, 2009 08:19 AM|LINK
Try this:
<html>
<body onbeforeunload="if(!Navigating){ alert('Browser close attempt is detected');return 'Browser close attempt
is detected'}else{Navigating=false;}">
<!-- Unimportant Sample Links & Forms to test all kinds of them, with/without event handlers... -->
<a href="http://www.google.com/">Navigate Away 1 (No Event Handler)</a><br>
<a href="http://www.google.com/" onclick="alert('Link Event Handler 1');">Navigate Away 2 (Event Handler 1)</a><br>
<a href="http://www.google.com/" id="link">Navigate Away 3 (Event Handler 2)</a><br>
<script language="javascript">
document.getElementById('link').onclick=function(){
alert('Link Event Handler 2');
};
</script>
<form action="http://www.google.com/">
<input type="submit" value="Navigate Away 1 (No Event Handler)">
</form>
<form action="http://www.google.com/" onsubmit="alert('Form Event Handler');">
<input type="submit" value="Navigate Away 2 (Event Handler)">
</form>
<!-- End of Unimportant Samples! -->
<script language="javascript">
var Navigating=false;
function ChargeHandler(obj,eve){
obj.oldHandler=obj[eve];
obj[eve]=function(){
if(obj.oldHandler!=null) obj.oldHandler();
Navigating=true;
};
}
//Add Navigating=true; to all links.onclick & all forms.onsubmit event handlers...
for(i=0;i<document.links.length;i++) ChargeHandler(document.links[i],'onclick');
for(i=0;i<document.forms.length;i++) ChargeHandler(document.forms[i],'onsubmit');
</script>
</body>
</html>
Reference: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23748383.html
Visit: www.msblogdirectory.com
www.dotnetspeaks.com
bhushangawale19
Member
389 Points
85 Posts
Re: How to fire some event after closing the page from(X)
May 19, 2009 08:36 AM|LINK
Hello,
You can use onbeforeunload event for this like:
<body onbeforeunload="alert('Closing');">
Thanks
Please mark it as answer If it really helped you
vinz
All-Star
116098 Points
16314 Posts
MVP
Re: How to fire some event after closing the page from(X)
May 19, 2009 08:38 AM|LINK
AFAIK,the only events that you can use when the browser is closed is the onunload or the onbeforeunload event.
Look here for more information.
http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx
http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
You may also use Page Methods as demonstrated in the link below:
http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.allMessageBox Controls for WebForms |Blog