How do I launch a webpage from a XUL app within XU

2019-08-20 19:02发布

What is the XULRunner equivalent of the following button handler?

function launch_page() {
    var win = Components.classes['@mozilla.org/appshell/window-mediator;1']
        .getService(Components.interfaces.nsIWindowMediator)
        .getMostRecentWindow('navigator:browser');
    win.openUILinkIn('http://www.google.com', 'window');
}

This does not do anything in my XUL app that's installed to Program Files using XULRunner --install-app ./foo.xpi.

Is there any way for my XUL app to launch the user's default browser to display a web page on a button click?

1条回答
Lonely孤独者°
2楼-- · 2019-08-20 19:59

This works for now:

// first construct an nsIURI object using the ioservice
var ioservice = Components.classes["@mozilla.org/network/io-service;1"]
    .getService(Components.interfaces.nsIIOService);

var uriToOpen = ioservice.newURI("http://www.google.com/", null, null);

var extps = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
    .getService(Components.interfaces.nsIExternalProtocolService);

// now, open it!
extps.loadURI(uriToOpen, null);

Anybody got a more standard way?

查看更多
登录 后发表回答