OPN详解
使用用户默认程序打开网站,文件,可执行文件等内容。
优点:
- 支持应用参数
- 更安全,因为它使用spawn而不是exec
- 跨平台
安装:
npm install opn
用法:
const opn = require('opn')
// 在默认图像程序打开图像
opn('unicorn.png').then(() => {
// image viewer closed
});
// 用默认浏览器打开网址
opn('http://sindresorhus.com');
// 用指定应用打开网址
opn('http://sindresorhus.com', {app: 'firefox'});
// 指定打开网址的浏览器参数
opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});opn(target, [options])target
类型: string
你要打开的东西。可以是URL,文件或可执行文件。
在默认应用程序中打开文件类型。例如,URL在默认浏览器中打开。
options
类型: Object
指定包含app和app参数的数组
相关推荐
liuxudong00 2020-11-19
wwzaqw 2020-11-11
lihaoxiang 2020-11-05
CrossingX 2020-11-04
xuegangic 2020-10-17
86417413 2020-11-25
83206733 2020-11-19
86276537 2020-11-19
83266337 2020-11-19
86256434 2020-11-17
zhouboxiao 2020-11-16
rise 2020-11-22
sssdssxss 2020-11-20
windle 2020-11-10
孙雪峰 2020-10-30
xfcyhades 2020-11-20
cheidou 2020-11-19