How to Detect Browser close of FIREFOX in asp.net

Posted by Bhavna81 under Regular Expressions on 1/28/2010 | Views : 6397 | Status : [Member] | Replies : 3
Hi to all
i m developing a website. in that i want to clear all the session variables, when user close the pop up window. i have tried the following script, but it works in IE only, not working in FireFox.
[code]
if((window.event.clientX<0) || (window.event.clientY<0))
{
alert("close");
}
if (event.altKey==true && event.keyCode==0 )
{
alert("ALT + F4 being pressed");
}
[/code]

Please Help to do it in fire fox.

thanks.




Responses

Posted by: Abhi2434 on: 1/28/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
window.event doesnt work with browsers other than IE. So it is always better to hook into events that are supported to all the browsers :

window.onbeforeunload = function () {


}


This is called everytime when the window is getting closed in most of the browsers.
See my reply here :
http://www.codeproject.com/tips/41771/How-to-detect-browser-close-when-browser-X-is-clic.aspx

Also you need to tactfully handle this event, as it will be called everytime you navigate away from the page.

I hope this will help you.
Cheers.

www.abhisheksur.com

Bhavna81, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 1/28/2010 [Member] Bronze

Up
0
Down
You can try the following code.

<html>

<body onUnLoad=' whatever function''>
</html>


Bur remember one thing onUnLoad will be called even if the page is posted back. So you have to handle that too in the Javascript code.

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Bhavna81, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 1/29/2010 [Member] Bronze

Up
0
Down
HI


ref this url

http://forums.asp.net/p/1153888/1891072.aspx

http://www.codeproject.com/KB/aspnet/browsercaps.aspx

Thanks
sagar

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Bhavna81, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response