javascript - window.opener.close()无效
问题描述
1.父页面window.open()打开新页面
var targetWeb=null;if(targetWeb){ targetWeb.focus();}else{ targetWeb=window.open(’https://segmentfault.com’,’segmentfault’);}
2.子页面中关闭父页面
window.opener.close();
发现子页面无法关闭父页面,会提示:Scripts may close only the windows that were opened by it但若换成:window.opener.location.href=’https://www.hao123.com’ 却可以,请问是什么原因
问题解答
回答1:
close 方法只能关闭由自己打开的window
回答3:<html><body>
<script type='text/javascript'>myWindow=window.open(’’,’’,’width=200,height=100’);myWindow.document.write('This is ’myWindow’');myWindow.document.write('<script>window.opener.close()</script>');myWindow.focus();myWindow.opener.document.write('This is the parent window');myWindow.close();</script>
</body></html>
尝试了这段代码,在父窗口中直接使用
myWindow=window.open(’’,’’,’width=200,height=100’); myWindow.close();
可以关掉子窗口,在子窗口中无效。
相关文章:
1. 为什么我ping不通我的docker容器呢???2. angular.js - angular指令中的scope属性中用&获取父作用域函数的问题3. docker镜像push报错4. docker不显示端口映射呢?5. dockerfile - 为什么docker容器启动不了?6. angular.js - angularjs的自定义过滤器如何给文字加颜色?7. docker api 开发的端口怎么获取?8. docker 17.03 怎么配置 registry mirror ?9. Docker for Mac 创建的dnsmasq容器连不上/不工作的问题10. angular.js使用$resource服务把数据存入mongodb的问题。

网公网安备