gpt4 book ai didi

jQuery 不关闭窗口

转载 作者:行者123 更新时间:2023-12-01 02:36:33 24 4
gpt4 key购买 nike

我正在为电子商务网站制作一个表单,供用户请求有关某个项目的 PDF。该表单工作正常并将用户发送到“感谢”页面。在感谢页面上,我让 jQuery 设置了 5 秒后关闭窗口的时间间隔。但它不起作用,在链接中嵌入关闭命令也不起作用。但是,如果“感谢”页面在新选项卡中打开,则该间隔将起作用。

这是 php 文件中的代码(在表单成功提交后调用)。

/* Results rendered as HTML */

$theResults = <<<EOD
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Thanks</title>
<script type="text/javascript" src="css/00000001/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
//wait a few seconds and close the window
setInterval(function()
{
window.close();
}, 5000);
});

</script>
<style type="text/css">
body{
background-color: transparent;
margin: auto auto auto auto;
border: none;
}

#general-copy{
background-color: transparent;
margin: -5px auto auto 0px;
position: absolute;
width: 300px;
height: 350px;
padding: 0px 15px 15px 15px;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 14px;
font-style: normal;
font-variant:normal;
font-weight:100;
text-align: justify;
z-index: 3;
}

</style>
</head>
<body><br /><br />
<div class="lettertext">
Thank you for your request.<br />
We will email you a pdf all about $item2Field.
<br><br>
<p style="font-size: 10px;">This window should close itself in 5 seconds.<br>
If it doesn't please click <a href="javascript:window.close()">here</a> to return to the site.
</p>
</div>
</body>
</html>
EOD;
echo "$theResults";


?>

如果您想观看此直播,可以尝试一下 here .

最佳答案

window.close @MDN(Mozilla 文档)

This method is only allowed to be called for windows that were opened by a script using the window.open method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

W3C norm on HTML5同意:

The close() method on Window objects should, if the corresponding browsing context A is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), and if the browsing context of the script that invokes the method is allowed to navigate the browsing context A, close the browsing context A (and may discard it too).

关于jQuery 不关闭窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5149552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com