Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jquery - Popup before window is closed

I want to open a custom popup box when browser close button is pressed, I want to ask a question to the users exiting that why are they leaving my site. I have checked quite few posts but the best thing I found is something like this post

http://stackoverflow.com/questions/10847156/jquery-dialog-box-before-closing-browser-window

But this just opens a browser default confirm box. I want to open a custom box like colorbox. My page is http://cwstudio.in/browserclose/

right now I am using alert function to open the popup but if I donot use the alert, the browser donot waits for my popup and just close it.

Any help is appreciated.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the javascipt window.onunload or jquery unload method:

Javascript:

 window.onunload = function(){
 //Do something
 }

Jquery:

 $(window).unload(function(){
 //Do something
 });

Update: If the user has blocked pop-ups then you can not do anything. However you can use a confirm box instead of showing popup:

var r = confirm("Are you sure you want to leave?");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...