node 打开浏览器


npm install --save opn


const opn = require('opn');
// 使用默认浏览器打开
// opn('http://sindresorhus.com');
// 使用默认软件打开图片
opn('unicorn.jpg').then(() => {
    // image viewer closed
    console.log('opened')
});

// 制定浏览器打开
// opn('http://sindresorhus.com', { app: 'firefox' });

// Specify app arguments  隐身模式打开chrome 浏览器
// opn('http://sindresorhus.com', { app: ['chrome', '--incognito'] });

opn.js 核心代码


const childProcess = require('child_process');

const cp = childProcess.spawn(cmd, args, cpOpts);

详情部分可以查看node 模块 child_process 部分

posted @ 2017-12-04 16:55  lake.hu  阅读(1916)  评论(0编辑  收藏  举报