我正在制作一个电子商务网站的表格供用户请求关于一个项目的PDF。 表单工作正常,并将用户发送到“谢谢”页面。 在感谢页面上,我有jQuery设置间隔5秒后关闭窗口。 但它不起作用,也不会将关闭命令嵌入到链接中。 但是,如果在“新建”选项卡中打开“谢谢”页面,则时间间隔将起作用。jQuery没有关闭窗口
这里是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。
真的,你应该避免需要新的窗口并关闭它们,它经常被阻止。如果您需要弹出窗口,请创建一个叠加层。 – Orbling 2011-03-01 01:29:54
@Orbling说的很多,你的场景看起来更像是一个糟糕的jQuery使用。 – yoda 2011-03-01 01:33:43
我可能会稍后将它作为叠加层进行转换,但现在弹出窗口就是我正在寻找的东西。 – mattelliottIT 2011-03-02 16:32:47