使用 window.location.replace 有没有办法更改端口?
使用 js 使用各种方法/赋值来更改浏览器 url。一切正常,但虽然我可以读取当前端口,但我似乎无法设置新端口 - 这可能吗? (我将浏览器从一个站点上的端口 80 重定向到另一个站点上的 node.js 端口,并且不想在节点盒上使用代理)。
提前干杯。
氮
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 set 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这确实在我的浏览器中有效,是的,我在重定向后在地址栏中看到了端口号:
这是一个也有效的替代方案:
This does work in my browser and yes I see the port number in the address bar after redirection:
and here is a alternative which also works:
对我来说“有效”(例如,无法连接!)
"works" (as in, fails to connect!) for me
好吧,我可能是个白痴;-) 谢谢没人和布莱恩 - 这些建议不起作用,但我解决了问题。进行重定向的网页上绝对没有其他代码,因此我对它失败的原因感到有点困惑。不过,我似乎添加了一个
未启用 JavaScript 的重定向。我未能在此处添加端口,因此是此代码执行重定向,而不是 window.location 内容。在此处添加端口解决了问题,并且可能是执行我想做的事情的正确位置。
氮
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
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