首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用nodejs打开默认浏览器并导航到特定的URL

如何使用nodejs打开默认浏览器并导航到特定的URL
EN

Stack Overflow用户
提问于 2011-12-14 14:29:22
回答 7查看 119.9K关注 0票数 172

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

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

我希望它是可移植的,这样它就可以在Windows/Mac/Linux上运行。

EN

回答 7

Stack Overflow用户

发布于 2012-11-16 23:32:42

使用open (以前称为opn),因为它可以处理跨平台问题。要安装:

$ npm install open

要使用以下命令:

const open = require('open');

// opens the url in the default browser 
open('http://sindresorhus.com');
 
// specify the app to open in 
open('http://sindresorhus.com', {app: 'firefox'});
票数 220
EN

Stack Overflow用户

发布于 2018-02-28 00:23:08

var url = 'http://localhost';
var start = (process.platform == 'darwin'? 'open': process.platform == 'win32'? 'start': 'xdg-open');
require('child_process').exec(start + ' ' + url);
票数 66
EN

Stack Overflow用户

发布于 2017-01-17 11:22:23

node-open为deprecated。现在使用open

const open = require('open')

await open('http://sindresorhus.com') // Opens the url in the default browser

await open('http://sindresorhus.com', {app: 'firefox'}) // Specify the app to open in
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8500326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档