安装
$ npm install --save opn
使用方法
const opn = require('opn');
// opens the image in the default image viewer
opn('unicorn.png').then(() => {
// image viewer closed
});
// opens the url in the default browser
opn('http://sindresorhus.com');
// specify the app to open in
opn('http://sindresorhus.com', {app: 'firefox'});
// specify app arguments
opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});
接口
在OS X上用命令open,在Windows上用start,在其他平台上使用xdg-open。
opn(target, [options])
返回生成的子进程的promise。 你通常不需要使用这个任何东西,但它可以是有用的,如果你想附加自定义事件监听器或直接对生成的进程执行其他操作。
target:
必需
类型:string
你想打开的东西。 可以是URL,文件或可执行文件。
在默认应用中打开文件类型。 例如。 URL在您的默认浏览器中打开。
options:
类型:object
wait
类型: boolean
默认: true
等待打开的应用程序在调用callback之前退出。 如果为false,则会在打开应用程序时立即调用。
在Windows上,您必须显式指定一个应用程序才能等待。
app:
类型: string,array
指定要使用的target打开的应用程序,或包含应用程序和应用程序参数的数组。
应用名称取决于平台。 不要在可重用模块中硬编码。 例如。 Chrome是OS X上的google chrome,Linux上的google-chrome和Windows上的chrome。
687

被折叠的 条评论
为什么被折叠?



