【问题标题】:Window opener is null when opened from webview in chrome app从 chrome 应用程序中的 webview 打开时,窗口打开器为空
【发布时间】:2014-05-29 09:08:19
【问题描述】:

这是我的问题:

我有一个 chrome 应用程序,它使用 webview 显示外部内容。在该内容中,有一个网页使用 window.open 并打开新窗口,这些窗口使用 window.opener 与页面进行通信。

但是,如果我使用 window.open 在 webview 中打开一个新窗口,则该窗口中的 window.opener 将设置为 null。有什么办法可以做到吗?

顺便说一句,我用这个钩子打开网页:

    webview.addEventListener('newwindow', function(e){
        e.preventDefault();
        window.open(e.targetUrl)
    })

【问题讨论】:

    标签: javascript google-chrome webview google-chrome-app


    【解决方案1】:

    下次我应该阅读文档。你需要做的就是使用window.attach方法,如:https://developer.chrome.com/apps/tags/webview

    webview.addEventListener('newwindow', function(e) {
      var newWebview = document.createElement('webview');
      document.body.appendChild(newWebview);
      e.window.attach(newWebview);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多