亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - window.opener.close() has no effect
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-06-26 10:52:27
0
3
1341

1. Parent page window.open() opens a new page

var targetWeb=null;
if(targetWeb){
    targetWeb.focus();
}else{
    targetWeb=window.open('https://segmentfault.com','segmentfault');
}

2. Close the parent page in the child page

window.opener.close();

If it is found that the child page cannot close the parent page, it will prompt: Scripts may close only the windows that were opened by it
But if it is replaced with: window.opener.location.href='https://www.hao123. com' but it works, what is the reason

PHP中文網(wǎng)
PHP中文網(wǎng)

認證高級PHP講師

reply all(3)
phpcn_u1582

大家講道理

The close method can only close the window opened by itself

黃舟

<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();

可以關(guān)掉子窗口,在子窗口中無效。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template