我有一个页面-a,我以 10 美元的价格提供一些东西,当用户试图离开该页面时,我想问他们是否想要以 5 美元的价格购买同样的东西。
因此,使用 onunload 我可以使用此代码显示一个带有我的消息的确认框。
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 = 'Hey Wait, Get everything mentioned below for $5, Click on Stay on this page?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload=goodbye;
现在,当用户单击留在此页面上时,我希望页面重定向到page-b,同样的东西只需 5 美元。
谁能帮我在哪里写额外的代码行?我做了快速研究,但找不到任何帮助。
先感谢您。