I have a desktop application, packaged using node-webkit. I need to open the default browser of the user on click of a link. I am using
window.open("www.google.com")
but this opens a new node-webkit window rather than opening a browser window. How do I open a browser window instead??
To use Node. js to open default browser and navigate to a specific URL, we can use the open package. const open = require("open"); open("http://example.com"); open("http://example.com", { app: "firefox" }); to call open to open the URL we pass into it.
Thanks to some creative engineers, it is now feasible to use Node. js modules in browsers, but not directly. Being able to call Node. js modules from JavaScript running in the browser has many advantages because it allows you to use Node.
This can be done using open npm package. app. listen(PORT, (err) => { if (err) console. log(err); else open(`http://localhost:${PORT}`, { app: "google chrome" }); });
NW.js (previously known as node-webkit) lets you call all Node.js modules directly from DOM and enables a new way of writing applications with all Web technologies. New way of writing native applications using web technologies: HTML5, CSS3, and WebGL. Full support for the features in browser.
To open a link in the user's default browser, you could use gui.Shell.openExternal("http://website.com")
. Checkout the documentation for gui.Shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With