[英]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.