如何使用nodejs打开默认浏览器并导航到特定URL [英] How to use nodejs to open default browser and navigate to a specific URL

查看:365
本文介绍了如何使用nodejs打开默认浏览器并导航到特定URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node.js编写应用程序。

I'm writing an application using Node.js.

我想创建的一个功能是打开默认的Web浏览器并导航到特定的URL 。

One of the functions I want to create is to open the default web browser and navigate to a specific URL.

我希望它可以移植,以便在Windows / Mac / Linux上运行。

I want it to be portable so that it runs on Windows/Mac/Linux.

推荐答案

使用 opn ,因为它将处理跨平台问题。安装:

Use opn because it will handle the cross platform issue. To install:

$ npm install opn

使用:

var opn = require('opn');

// opens the url in the default browser 
opn('http://sindresorhus.com');

// specify the app to open in 
opn('http://sindresorhus.com', {app: 'firefox'});

这篇关于如何使用nodejs打开默认浏览器并导航到特定URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆