我正在使用以下代码,以便如果用户关闭浏览器按钮,它会显示一个确认框,无论是否留在页面上。
我想要做的是,如果有人关闭浏览器,它应该显示一个图像,带有“是”或“否”选项。单击“是”时应关闭浏览器,单击“否”时不应关闭浏览器。图像必须显示在同一窗口中,而不是任何弹出窗口中。是否有可能做到这一点,还是我对 JavaScript 期望过高?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var exit=true;
function confirmExit()
{
if(exit)
{
window.location.href = "?p=exit";
}
if(exit)
return "Wait! Don't Leave Empty Handed!\n\nThank you for taking the time to check out our offer! Before you go we have a complimentary crash to help you succeed. Click the 'Cancel' or 'Stay On This Page' button if you're interested!";
}
</script>
</head>
<body onbeforeunload="return confirmExit()">
</body>
</html>