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' 却可以,请问是什么原因
还是在一本书上找到了答案:浏览器的主窗口,在没有得到用户的允许时不能关闭它。弹窗是可以不经过用户的允许关闭自己。