window.opener

概述

返回打开当前窗口的那个窗口的引用,例如:在window A中打开了window B,B.opener 返回 A.

语法

var objRef = window.opener;

例子

 if (window.opener != indexWin) {
     referToTop(window.opener);
 }

备注

如果当前窗口是由另一个窗口打开的, window.opener保留了那个窗口的引用. 如果当前窗口不是由其他窗口打开的, 则该属性返回 null.

规范

DOM Level 0 不属于任何标准.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
openerChrome Full support 1Edge Full support 12Firefox Full support 1IE No support NoOpera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0

Legend

Full support  
Full support
No support  
No support

注意:在Chrome78最近的几个版本,如果A、B页面跨域,A页面中打开B页面,在B页面使用console.log在控制台打印window.opener会报跨域的错误。