asp.net - Detecting JavaScript popup window close event in browser - Stack Overflow

I am opening a Javascript popup window using window.open() function and have close button on it .I want

I am opening a Javascript popup window using window.open() function and have close button on it .I want to detect the the close event of that window in IE,Firefox and chrome as I want to clear session variables and redirect to some other page. I tried using window.onbeforeunload event but it is executing at every postback. Any suggestions will be appreciated.

I am opening a Javascript popup window using window.open() function and have close button on it .I want to detect the the close event of that window in IE,Firefox and chrome as I want to clear session variables and redirect to some other page. I tried using window.onbeforeunload event but it is executing at every postback. Any suggestions will be appreciated.

Share Improve this question edited Aug 18, 2021 at 7:40 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 3, 2012 at 5:57 swapnilswapnil 811 gold badge3 silver badges10 bronze badges 4
  • Where do you need to "catch" the popup being closed - in the parent window or in the popup? Where do you need to run code - in the parent window or in the popup? And what does the code need to do? – Ian Commented Nov 3, 2012 at 6:03
  • I need to catch event in same popup window.The code clears any session variables that are used and will redirect to some other page after closing the popup. I also tried widow.opener.location in window.onbeforeunload but it does not get redirected. – swapnil Commented Nov 3, 2012 at 6:06
  • stackoverflow./questions/3888902/… – ChaosClown Commented Nov 3, 2012 at 6:07
  • So you mean that when the popup is closed, you need to clear session variables and then redirect what? Redirect the parent page to somewhere else? And how do you "clear any session variables"? Do you make an AJAX request? – Ian Commented Nov 3, 2012 at 6:14
Add a ment  | 

3 Answers 3

Reset to default 2

There is a very simple solution to your problem.

First make a new object which will open up a pop like this :

var winObj = window.open('http://www.google.','google','width=800,height=600,status=0,toolbar=0');

In order to know when this popup window is closed, you just have to keep checking this with a loop like the following :

var loop = setInterval(function() {   
    if(winObj.closed) {  
        clearInterval(loop);  
        alert('closed');  
    }  
}, 1000); 

Now you can replace alert with any javascript code you want.

Have Fun! :)

You need an event handler for that there are just these two one could use. So as you said you will have history back and refresh triggering your event too .

Please view this post

Another solution is that you set popup size to fullscreen and make your own close botton. Im sorry javascript is running out of solutions here :-/

$(window).bind('unload', function(){
    // ...
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745616787a4636283.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信