Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Node js redirect to a url and display it in another new browser?

Tags:

node.js

I want to use node js redirect to the url and display the url in a new browser, can that be happening?

like image 283
Jianyuan Ma Avatar asked Nov 16 '25 19:11

Jianyuan Ma


2 Answers

The easiest way to do this cross browser is to use the "open" npm module This module allows you to open a new browser window and designate a url to go to

npm install open --save

then in your request when you want to open the new browser and load the url simply call

open( 'http://urltodirect.to', function (err) {
  if ( err ) throw err;    
});

That will open a new browser window and send the tab to http://urltodirect.to

Hope this helps!

like image 134
kkemple Avatar answered Nov 18 '25 07:11

kkemple


Node Js is a server side technology which can redirect the browsers request to a new location but cannot instructed the browser to open a new window.

You need to use client side javascript to ask the browser to open another window see here:

http://www.w3schools.com/jsref/met_win_open.asp

or use target="_blank" within the link itself.

like image 44
Richard Avatar answered Nov 18 '25 09:11

Richard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!