添加其他功能以退出页面弹出消息

时间:2018-09-25 01:35:54

标签: javascript popup warnings exit

我想向基本的普通javascript退出页面弹出窗口添加一个附加功能。基本上,我已设置好页面,因此当用户尝试退出页面时,将显示一条消息,提示“您真的要离开吗”,并带有“确定”和“取消”选项。我要设置它,以便当用户单击“确定”时,它将把他们重定向到另一个网站。我没有太多的编码经验,所以不确定是否可行。这是我正在使用的代码:

<h1 id="home">Warn before leaving the page</h1>

<script>
// Warning before leaving the page (back button, or outgoinglink)
window.onbeforeunload = function() {
   return "Do you really want to leave?";
   //if we return nothing here (just calling return;) then there will be no pop-up question at all
   //return;
};
</script>

<a href="http://google.com/</a>

任何帮助将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:0)

这是您应避免执行的操作,因为这会降低用户体验。这也是this post的重复。