window.opener - ythy/blog GitHub Wiki

  • window.opener refers to the window that called window.open( ... ) to open the window from which it's called
  • window.parent refers to the parent of a window in a <frame> or <iframe>
  • window.top refers to the top-most window from a window nested in one or more layers of <iframe> sub-windows

Those will be null (or maybe undefined) when they're not relevant to the referring window's situation. ("Referring window" means the window in whose context the JavaScript code is run.)

应用实践: 需要接收新窗口返回值

  1. 定义事件名称 POPEvent
  2. 主页面监听事件 $(document).on('POPEvent', this.onOpenerBack, null);
  3. pop派发事件 window.opener.$('body').trigger( 'POPEvent', ['data'] );
⚠️ **GitHub.com Fallback** ⚠️