简体   繁体   English

从chrome app中的webview打开时,window opener为null

[英]Window opener is null when opened from webview in chrome app

here is my problem: 这是我的问题:

I have a chrome application that, using webview, shows external content. 我有一个chrome应用程序,使用webview显示外部内容。 In that content, there is a webpage that uses window.open and to open new windows and those windows use window.opener to communicate back to the page. 在该内容中,有一个网页使用window.open并打开新窗口,这些窗口使用window.opener与页面进行通信。

However, if i use window.open to open a new window inside a webview, window.opener in that window is set to null . 但是,如果我使用window.open在webview中打开一个新窗口,则该窗口中的window.opener将设置为null Is there any way to make this work? 有没有办法让这项工作?

Btw i use this hook to open webpages: 顺便说一句,我用这个钩子打开网页:

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

I should read the docs next time. 我下次应该阅读文档。 All you need to do is use window.attach method as shown in: https://developer.chrome.com/apps/tags/webview 您需要做的就是使用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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM