search

Home  >  Q&A  >  body text

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

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

黄舟黄舟2876 days ago685

reply all(4)I'll reply

  • 阿神

    阿神2017-04-17 13:49:08

    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.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:49:08

    osx

    open -a "http://127.0.0.1/"

    windows

    explorer "http://127.0.0.1/"

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:49:08

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:49:08

    http://www.nightmarejs.org/

    Take a look at this.

    reply
    0
  • Cancelreply