使用 javascript window.location 更改端口

Changing port with javascript window.location

目前我正在编辑的页面有一个 JS 菜单。这包含诸如;

{
    xtype: 'tbbutton',
    text: 'Home',
    width: 60,
    handler: function() { window.location = 'index.php'; }
},

然而,由于服务器的设置方式,我需要更改页面之间的端口号,因为有些无法处理页面上使用的 php。 (试图基于别人的程序来满足我的目的)

从我在这里看到的情况来看,这表明这应该有效

{
    xtype: 'tbbutton',
    text: 'Home',
    width: 60,
    handler: function() { window.location.port = 80; window.location = 'index.php'; }
},

所以我在 index.php 中的目标是在端口 80 上,page1.html、page2.html 在端口 81 上。用户可以通过单击在它们之间跳转,而不管港口。该页面可以通过家庭网络(使用 192. 地址)或通过网络(使用 public IP)访问,因此我不想每次都设置域。

有什么想法吗?

将 window.location 设置为完整的 URL,其中包含端口号:

window.location = "http://adomain.com:80/index.php";

如果要使用当前域,则可以使用window.location.hostname构造URL以使用当前主机。

window.location = "http://" + window.location.hostname + ":80/index.php";

尝试像这样更改您的代码

{
xtype: 'tbbutton',
text: 'Home',
width: 60,
handler: function() { window.location = 'index.php'; }
},

使用location.port = 80;在您的 index.php 中,这将起作用

使用location.port = 80;将更改您当前的端口。