【发布时间】:2014-04-17 11:59:52
【问题描述】:
我正在尝试在浏览器窗口/标签关闭时添加一个带有确定/取消的调查确认框。 我需要在单击确定按钮时将用户重定向到调查链接。
尝试用下面的代码来实现。
var leave_message = 'Wait! Would you like to respond to a quick Survey?'
function bye(e) {
if (!e) e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
e.returnValue = leave_message;
if (confirm(leave_message)) {
window.open("www.surveylink.com");
}
}
window.onbeforeunload = bye;
请建议上面的代码不起作用。
【问题讨论】:
-
使用 var ans=confirm(leave_message); if (ans==true){//重定向}
-
在关闭窗口/选项卡时无法执行任何代码,这是违反安全规定的。广告软件曾经这样做是为了阻止您摆脱他们的广告。
-
你永远不会得到答案,因为它不可能stackoverflow.com/questions/276660/…
-
@PratikJoshi 和你原来的评论有点矛盾,不是吗?
-
@RGraham,我给了他解决方案
标签: jquery javascript