简体   繁体   English

有什么方法可以使用node js从其他计算机打开浏览器吗?

[英]Is there any way to open a browser from different machine using node js?

I am just curious to know, is there any possibility to open/trigger a browser from different machine in same LAN using NodeJS. 我只是想知道,是否有可能使用NodeJS从同一LAN中的其他计算机打开/触发浏览器。

I have gone through node's default 'http.createServer()' and browserSync. 我已经通过了节点的默认'http.createServer()'和browserSync。 Using them I can create a server and open the page in other machine's. 使用它们,我可以创建服务器并在其他计算机上打开页面。 But dont know how to trigger the browser/tab automatically in them. 但是不知道如何在其中自动触发浏览器/选项卡。

Thanks! 谢谢!

This is a massively over simplified solution to your problem, and as you're aware there are significant security considerations around this functionality. 这是对您的问题的过度简化的解决方案,并且您已经知道,围绕此功能有很多安全方面的考虑。

However, using open this can be done quite easily on a local network (providing the correct firewall rules are in place). 但是,在本地网络上使用open可以很容易地做到这一点(只要正确的防火墙规则到位)。

Computer B (the machine the browser should open on): 计算机B(打开浏览器的计算机):

var http = require('http');
var open = require("open");

function handleRequest(request, response){
    open("http://www.google.com", "firefox");
}

var server = http.createServer(handleRequest);

server.listen(8080, function(){
    console.log("Server listening on: http://localhost:8080");
});

Computer A (the machine to trigger the browser opening from): 计算机A(触发浏览器打开的计算机):

var http = require('http');

var options = {
  host: '<Computer A IP address>',
  port: 8080,
  path: '/'
};

http.request(options).end();

While running the code on computer B, if you run the computer A code then it should open Firefox at http://www.google.com on computer A. 在计算机B上运行代码时,如果运行计算机A上的代码,则应在计算机A上位于http://www.google.com上打开Firefox。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在节点的浏览器中打开 html - Is there a way to open html in a browser in node 使用浏览器检测其他机器 - Detect Different Machine using Browser Node.js:如果使用 Pupeteer 打开,则关闭浏览器 - Node.js: close browser if its open using Pupeteer 有什么方法可以使用JS将类似浏览器的实例流式传输到客户端? - Any way to stream a browser-like instance to a client using JS? `this`的默认绑定与Chrome浏览器和Node.js不同 - Default binding of `this` is different from Chrome browser and Node.js 有什么办法可以编写“统一”的 Node.js 和浏览器 JS? - Is there any way I can write “unified” Node.js and browser JS? 如何在使用angular js从任何一个选项卡注销时关闭与特定域相关的所有浏览器打开的选项卡 - How to close browser all open tabs related to a specific domain while logout from any of those one tab using angular js 有没有办法从Facebook浏览器(onClick)重定向用户强制URL在chrome或任何其他浏览器中打开? - Is there a way to redirect users from facebook browser (onClick) enforcing the URL to open in chrome or any other browser? 有没有办法使用 Node.js 获取文件的修改日期? - Is there any way to get the date modified of a file using Node.js? 使用节点JS从浏览器的用户输入中检索Twitter - Using node JS to retrieve twitter from user input from browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM