开发者

Popup on exiting the page Javascript jQuery

I would like to display a feed back pop-up to the user if he/she exits (close the window/close the tab) the page. Same should work if he/she clicks on third party links (any other host) on the page as well but not the self links (belong to the same host). I have tried window.onbeforeunload which seems to work on IE exit only. Could someone help me开发者_StackOverflow with this?

Thanks, Racky


Use the unload() event:

http://api.jquery.com/unload/

Here's the example taken from that page:

$(window).unload( function () { alert("Bye now!"); } );

This will called when you refresh the page, because technically you aren't submitting it, you are asking for it again, which means you're leaving the one you're on.

Self links shouldn't cause a reload of the page so you'll be fine. Self links either need to be #anchorname or doSomeJavaScript(); return false;

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜