【问题标题】:How do I redirect the window that opened a popup window to a new page by clicking a button in the popup window?如何通过单击弹出窗口中的按钮将打开弹出窗口的窗口重定向到新页面?
【发布时间】:2013-04-25 15:57:30
【问题描述】:

我有一个打开弹出窗口的页面,在弹出窗口中,我有一个链接应该将打开当前窗口的窗口重定向到名为 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>

【问题讨论】:

    标签: javascript popup window


    【解决方案1】:

    变化:

    window.opener("privacy.html");
    

    收件人:

    window.opener.location.href = "privacy.html";
    

    【讨论】:

      猜你喜欢
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      • 2013-06-06
      • 2018-12-18
      • 2021-03-21
      相关资源
      最近更新 更多