Nodejs打开浏览器


有没有为nodejs编译完成后,还要打开浏览器,输入网址,而感到烦恼呢?放心,这就来拯救你。

今天介绍的这个模块叫做open模块。它的功能就是主动打开浏览器,免去你的一些烦恼。

安装

$ npm install opn --save

用法

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']});

怎么样?很简单吧,还等什么呢。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM