Jianyuan Ma
Jianyuan Ma

Reputation: 325

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

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

Upvotes: 4

Views: 27384

Answers (4)

Pratap Tondwalkar
Pratap Tondwalkar

Reputation: 21

One small trick that works for is, I have a redirect on the link which I want to open in a new tab.

And added target="_blank" in my form

<form method='post' action="/post/URL" target="_blank">
...
</form>

Upvotes: 1

kkemple
kkemple

Reputation: 992

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!

Upvotes: 4

Kyri Elia
Kyri Elia

Reputation: 1007

You can redirect to a new URL with Node as part of a server request if you use the Express framework's redirect method.

However you can't display the URL in a new browser with Node, as this is front-end work. You could use target=_blank within your HTML link in order to do this.

Upvotes: 1

Richard
Richard

Reputation: 22016

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.

Upvotes: 2

Related Questions