![](/img/trans.png)
[英]How can I redirect a page to previous url from new url that is opened using window.location.href on clicking exit button?
[英]How do I redirect the window that opened a popup window to a new page by clicking a button in the popup window?
我有一個打開彈出窗口的頁面,在彈出窗口中,我有一個鏈接,該鏈接應將打開當前窗口的窗口重定向到名為privacy.html的頁面。
我知道我應該使用window.opener來引用該窗口,我發現了另一個問題,解決方案是使用setInterval。 這可能對此有用。
無論如何,這是我的代碼,無法重定向打開器窗口,但您可以看到我正在嘗試執行的操作。
<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>
更改:
window.opener("privacy.html");
至:
window.opener.location.href = "privacy.html";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.