npm模块之opn使用教程(译)

原文链接

安装

$ 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:
类型: stringarray

指定要使用的target打开的应用程序,或包含应用程序和应用程序参数的数组。

应用名称取决于平台。 不要在可重用模块中硬编码。 例如。 Chrome是OS X上的google chrome,Linux上的google-chrome和Windows上的chrome

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值