Arg
Arg

Reputation: 1916

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. 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.

However, if i use window.open to open a new window inside a webview, window.opener in that window is set to 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)
    })

Upvotes: 3

Views: 2453

Answers (1)

Arg
Arg

Reputation: 1916

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

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

Upvotes: 2

Related Questions