Window.get([window_object])

用途:获取指定window_object窗口(未指定时默认为当前窗口)的窗口对象

  • window_object {DOM Window} (可选) DOM窗口对象
  • Returns {Window} the native Window object

如果 window_objectiframe, 该方法将返回其顶层窗口的 Window 对象.

  1. // 获取当前窗口的`Window`对象
  2. var win = nw.Window.get();
  3.  
  4. /获取iframe的窗口
  5. var iframeWin = nw.Window.get(iframe.contentWindow);
  6.  
  7. //返回true
  8. console.log(iframeWin === win);
  9.  
  10. // 创建窗口并获取它的窗口对象
  11. nw.Window.open('https://github.com/nwjs/nw.js', {}, function(new_win) {
  12. // do something with the newly created window
  13. });