开发者

Using window.location.replace is there any way to change port as well?

开发者 https://www.devze.com 2023-03-28 21:58 出处:网络
Using the various methods/assignments to change the browser url using js.All work fine but whilst I can read the current port, I can\'t seem to se开发者_StackOverflowt the new port - is this possible

Using the various methods/assignments to change the browser url using js. All work fine but whilst I can read the current port, I can't seem to se开发者_StackOverflowt the new port - is this possible ? (I'm redirecting the browser from port 80 on one site to a node.js port on another site and don't want to use a proxy on the node box).

Cheers in advance.

N


This does work in my browser and yes I see the port number in the address bar after redirection:

window.location.replace( 'http://somedomain.com:1234/' );

and here is a alternative which also works:

window.location.port = 1234;


window.location = "http://stackoverflow.com:1234"

"works" (as in, fails to connect!) for me


Ok I may have been an idiot ;-) Thanks nobody and Brian - those suggestions didn't work but I solved the problem. The webpage doing the redirection had absolutely no other code on it so I was at a bit of a loss as to why it was failing. However it seems I had added a

<META HTTP-EQUIV=REFRESH 

for the redirection where javascript wasn't enabled. I had failed to add the port here and so it was this code that was doing the redirection, not the window.location stuff. Adding the port here solved the problem and is probably the right place to do what I was trying to do.

N

0

精彩评论

暂无评论...
验证码 换一张
取 消