const open = require('open');
// opens the url in the default browser
open('http://sindresorhus.com');
// specify the app to open in
open('http://sindresorhus.com', {app: 'firefox'});
const open = require('open')
await open('http://sindresorhus.com') // Opens the url in the default browser
await open('http://sindresorhus.com', {app: 'firefox'}) // Specify the app to open in
const open = require('open');
(async () => {
// Opens the image in the default image viewer and waits for the opened app to quit.
await open('unicorn.png', {wait: true});
console.log('The image viewer app quit');
// Opens the URL in the default browser.
await open('https://sindresorhus.com');
// Opens the URL in a specified browser.
await open('https://sindresorhus.com', {app: 'firefox'});
// Specify app arguments.
await open('https://sindresorhus.com', {app: ['google chrome', '--incognito']});
})();
9条答案
按热度按时间qaxu7uf21#
使用open(以前称为
opn
),因为它将处理跨平台问题。要安装:用途:
3qpi33ja2#
o2g1uqev3#
node-open是deprecated。现在使用open:
fnvucqvd4#
您可能需要使用的值实现开关。。
然后根据平台使用
spawn("open")
或spawn("xdg-open")
?hec6srdp5#
安装:
使用方法:
qoefvg9y6#
Windows + Express
gdx19jrr7#
最简单和最整洁的方法,恕我直言,是使用名为openurl的npm包。执行
npm install openurl
。您可以在Nodejs REPL中真实的尝试require("openurl").open("http://stackoverflow.com/questions/8500326/how-to-use-nodejs-to-open-default-browser-and-navigate-to-a-specific-url")
你也可以发送电子邮件与它如果需要出现这样的;
require("openurl").open("mailto:janedoe@example.com")
yduiuuwa8#
nkoocmlb9#
简单使用
对我很有效。