How to disconnect JavaScript popup from opener

删除回忆录丶 提交于 2019-11-29 07:09:31

If the page in the child window is in your control, you can assign null to the opener in the child page:

window.opener = null;

By making this as the first statement in your javascript.

If the page is not in your control or is in a different domain, then do it while opening:

popup = window.open(this.href, '_blank', 'width=512,height=512,left=200,top=100');
popup.opener = null;

From doc:

In some browsers, a rel="noopener" attribute on the originating anchor tag will prevent the window.opener reference from being set.

See all supported browsers: https://caniuse.com/#search=noopener

Also, for older browsers use no-referrer: https://mathiasbynens.github.io/rel-noopener/

So the fix is do rel="noreferrer noopener" wherever you are using target="_blank"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!