Open links in a new tab using <webview>

2,509 views
Skip to first unread message

Anderson Quadros

unread,
May 14, 2014, 9:55:39 AM5/14/14
to chromi...@chromium.org
Hello everybody .

I'm trying to create an app that contains a web page using a <webview> .
The basic I got. My app is opening the page, but the links that open popups do not work .
I've read about the Event Listener " newwindow " . I do not know how to apply in my code .
In my html page I placed the following : <script src="controls.js"> < / script >
And controls.js file put the code :

onload = function() {
var webview = document.getElementById("SISTEMA");
var indicator = document.querySelector(".indicator");
  
var loadstart = function() {
 indicator.innerText = "carregando...";
}
var loadstop = function() {
 indicator.innerText = "";
}
webview.addEventListener("loadstart", loadstart);
webview.addEventListener("loadstop", loadstop);

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


Where am I going wrong ?
Attached is my project . Many thanks for the help .
weboffice.zip

Ken Rockot

unread,
May 14, 2014, 10:26:45 AM5/14/14
to Anderson Quadros, Chromium Apps, Renaud Paquay
Can you verify that you're receiving the newwindow event? It looks like your code will handle new-window links be creating a new webview in the app window and loading target url there. Maybe your new webview element obscured by the original?

If you want to open links in a new browser window, you should instead write your newwindow handler as:

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

Note that this will open the URL using the system's default browser, which may not be Chrome. If it is Chrome, and a Chrome browser window is already open for the app's active profile, the target will load in a new tab within that window.

There is currently no way to always open a URL in a new Chrome tab from within an app, but that is coming. Not sure what the API will look like, but +rpaquay who worked on that.


--
You received this message because you are subscribed to the Google Groups "Chromium Apps" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-app...@chromium.org.
To post to this group, send email to chromi...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-apps/.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Anderson Quadros

unread,
May 14, 2014, 10:45:56 AM5/14/14
to Ken Rockot, Chromium Apps, Renaud Paquay
it works! thanks!

-----------//------------

Matt Cook

unread,
Feb 9, 2016, 4:11:21 PM2/9/16
to Chromium-Apps-Announce, dia...@gmail.com, rpa...@chromium.org
Was the tab API for apps released? We would like to add tab functionality to our kiosk application which uses <webview>, ideally without re-rolling our own tab functionality using a 'newwindow' event listener. 

Saier Li

unread,
Oct 13, 2016, 3:42:19 AM10/13/16
to Chromium-Apps-Announce, dia...@gmail.com, rpa...@chromium.org
it is ok

在 2014年5月14日星期三 UTC+8下午10:26:45,Ken Rockot写道:
Reply all
Reply to author
Forward
0 new messages