如何使用javascript重定向父页面

How to redirect parent page using javascript

本文关键字:重定向 何使用 javascript      更新时间:2023-09-26

我想问你如何将父页面从pup-up页面重定向到某个url?我尝试了几个选项作为parentopener,但都不起作用。请帮我理解出了什么问题。

这是我使用的代码:

<html>
<head>
<script>
  function openWin(){
       myWindow=window.open('','','width=200,height=100');
       myWindow.document.write("<p>This is 'myWindow'</p> <button onclick='"window.opener.location.href = ='http://www.google.com'; window.close();'">refresh</button>");
       myWindow.focus();
  }
</script>
</head>
<body>
   <input type="button" value="Open window" onclick="openWin()" />
 </body>
 </html>

您的代码中有一个错误。应该是

myWindow.document.write("<p>This is 'myWindow'</p> <button onclick='"window.opener.location.href = 'http://www.google.com'; window.close();'">refresh</button>");

即在'http://www.google.com'之前移除额外的=