开发者

How can I capture window close event?

开发者 https://www.devze.com 2023-03-07 19:09 出处:网络
I have Ajax DHTML window. I want to redirect the page on different location when some one close开发者_开发百科d the window by clicking on cross image of window.

I have Ajax DHTML window. I want to redirect the page on different location when some one close开发者_开发百科d the window by clicking on cross image of window.

I have used following code to open window.

ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", popupURL, "Error Message", "width=450px,height=200px,resize=1,scrolling=1,center=1")


There are two events that can help you here, onbeforeunload and onunload. The onunload event may allow you to achieve what you need to, if it is fired by the browser.


Technically, the event you want to bind your callback to is called onUnload. Downside is that people got so damn annoying with triggering javascript pop-ups when leaving a website or closing a window, most the time it is considered 'user abuse' and blocked by most browsers (much like the javascript ability to overwrite the status bar/etc.

<opinion> Welcome to the web, its a stateless medium. See my comment below.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号