I want to show survey in pop-up window when users leaves page.
So I want to leave page only when he answers all the questions of survey and/or close the pop-up window... How can I do that?
I try this code
$(document).ready(function () {
function exitpop() {
my_window = window.open("", "mywindow1", "status=off,toolbar=off,location=off,menubar=off,directories=off,resizable=off,scrollbars=off,height=800,width=800");
});
}
$(window).unload(function () {
exitpop();
});
});
But it blocks by majority of browsers and don't pause clicked action(going to other page or closing the window). What is the best way to do that?
I want to show survey in pop-up window when users leaves page.
So I want to leave page only when he answers all the questions of survey and/or close the pop-up window... How can I do that?
I try this code
$(document).ready(function () {
function exitpop() {
my_window = window.open("http://www.google.", "mywindow1", "status=off,toolbar=off,location=off,menubar=off,directories=off,resizable=off,scrollbars=off,height=800,width=800");
});
}
$(window).unload(function () {
exitpop();
});
});
But it blocks by majority of browsers and don't pause clicked action(going to other page or closing the window). What is the best way to do that?
Share Improve this question asked Nov 14, 2011 at 7:55 Chuck NorrisChuck Norris 15.2k15 gold badges95 silver badges127 bronze badges 5- try here: stackoverflow./questions/1025935/… – Alon Commented Nov 14, 2011 at 7:57
- 3 No offense but what you're trying to do is extremely obnoxious. There's a reason browsers block it. Circumventing it shouldn't be your goal. – Spencer Ruport Commented Nov 14, 2011 at 7:59
- I want to show survey in pop-up, then after closing it continue previous action... – Chuck Norris Commented Nov 14, 2011 at 8:00
- 4 If you want the user to do a survey, make a "notify bar" at the top of the page. But do not do anything popup related when the user wants to LEAVE your page. There's a reason he wants to leave, letting him fill out a survey at that point in time will - to a very high degree - result in the user having a bad attitude and thus promising his previous feelings about your page. – Sam Commented Nov 14, 2011 at 8:29
- 2 @SpencerRuport I would add that its not ALWAYS extremely obnoxious (although most uses I've seen have been by obnoxiously bad, stupid, and/or spammy sites). In our case we have a huge web form, with several textareas and a bunch of other form fields, in an RIA app for admin users. A user could perceivably spend 20 minutes on a form and then accidentally do something that triggers the back button, or a refresh, or loading another page. A highly requested feature is to prevent them from accidentally leaving the page without confirming. – B Robster Commented Dec 5, 2012 at 20:47
2 Answers
Reset to default 3Try Using window.onbeforeunload
event ..
have an idea from the follow code snippet. i am using this type of code to confirm use to before leaving the page.. means either it is close tab or refresh the page...
But you have to track when it is refresh or close.. both means same to beforeunload..
you can't use directly use them either unload
or beforeunload
- they do not differ between window close, Try this may be it will work according to your requirements.
http://docs.jquery./Events/unload#fn
jQuery:
$(window).unload( function () { alert("Bye now!"); } );
or javascript:
window.onunload = function(){alert("Bye now!");}
For more information follow this: https://developer.mozilla/en/DOM/window.onclose
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function confirmBeforeUnload(e) {
var e = e || window.event;
// For IE and Firefox
if (e) {
e.returnValue = 'Any string';
}
// For Safari
return 'Any string';
}
function goodbye(e) {
if (!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload = goodbye;
</script>
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
open survey content in modal for interaction... follow these links to create modal popup on your page ..
http://choosedaily./1178/15-jquery-popup-modal-dialog-plugins-tutorials/
http://www.queness./post/77/simple-jquery-modal-window-tutorial -- follow this step by step tutorial with code to create modal popup..
Is it necessary to make users fill out a survey? If not, then you could replace the contents of the body so the user sees it in the background.
var done = 0;
window.onbeforeunload = function() {
if (done != 1) {
done = 1;
document.getElementsByTagName('body')[0].innerHTML = "new content goes here";
return "Howdy there. Why don't you stick around for a moment and take our survey?";
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744165562a4561290.html
评论列表(0条)