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.
- 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
3 Answers
Reset to default 2There 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条)