繁体   English   中英

如何使用JavaScript重定向父页面

[英]How to redirect parent page using javascript

我想问你如何从上一页将父页面重定向到某个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'之前的多余=

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM