javascript - window.opener.close() has no effect
PHP中文网
PHP中文网 2017-06-26 10:52:27
0
3
1180

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中文网
PHP中文网

认证高级PHP讲师

reply all (3)
phpcn_u1582

    大家讲道理

    The close method can only close the window opened by itself

      黄舟


      ");
      myWindow.focus();
      myWindow.opener.document.write("This is the parent window");
      myWindow.close();


      尝试了这段代码,在父窗口中直接使用
      myWindow=window.open('','','width=200,height=100'); myWindow.close();

      可以关掉子窗口,在子窗口中无效。

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!