我有一个打开弹出窗口的页面,在弹出窗口中,我有一个链接应该将打开当前窗口的窗口重定向到名为privacy.html的页面。
我知道我应该使用window.opener来引用那个窗口,我发现了另一个问题,解决方案是使用setInterval。这对此可能有用。
How to focus on a previously opened window using window.open()
无论如何这是我的代码,它不能重定向开启窗口,但你可以看到我正在尝试做什么。
<script type="text/javascript">
function validateEmail() {
var emailRule = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (emailRule.test(document.forms[0].email.value)) {
document.getElementById("body").innerHTML = "Thank you for signing up for our newsletter! You will recieve a confirmation email shortly.";
setTimeout("window.close()", 3000);
}
else {
document.getElementById("message").innerHTML = "Please enter a valid email address";
}
}
function privacyWindow() {
window.opener("privacy.html");
}
</script>
</head>
<body id="body">
<p>If you sign up for our newsletter you will be entered into a drawing to win free clothes every month!</p>
<p id="message"><br></p>
<form action="" onsubmit="validateEmail();">
<p>Email: <input type="text" name="email"/>
<input type="button" value="Sign up" onclick="validateEmail();"/></p>
<br>
<input type="button" value="No thanks" onclick="window.close()"/>
<br>
</form>
<p><a href="" onclick="privacyWindow();">Privacy Policy</a></p>
</body>
</html>
答案 0 :(得分:1)
变化:
window.opener("privacy.html");
要:
window.opener.location.href = "privacy.html";