How do I launch a webpage from a XUL app within XULRunner?

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?

Answers:

Answer

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?

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.