gpt4 book ai didi

javascript - 如何使用javascript重定向父页面

转载 作者:行者123 更新时间:2023-11-30 18:02:09 25 4
gpt4 key购买 nike

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

关于javascript - 如何使用javascript重定向父页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16704195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com