node.js - 求问node如何自动打开浏览器,并打开指定网址
黄舟
黄舟 2017-04-17 13:47:08
0
4
683

求问node如何自动打开浏览器,并打开指定网址

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
阿神

node.js opens the browser

  • Method 1
    Open the system default browser. For example, if you set firefox as the default browser, it will open firefox. Create a new js file with the following content:

var c = require('child_process');
c.exec('start http://www.baidu.com');

Then execute it!
Open the specified browser, such as chrome,

var c = require('child_process')
c.exec("C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe http://sosout.com/"); // 前面是浏览器安装目录,后面是打开的链接
  • Method 2
    Use a third-party library. It is recommended to use opn. This library has some optimizations.

大家讲道理

osx

open -a "http://127.0.0.1/"

windows

explorer "http://127.0.0.1/"
黄舟

Use this library to open. In fact, it just encapsulates the commands for calling browsers in different operating systems

Ty80

http://www.nightmarejs.org/

Take a look at this.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template