2016-01-24 105 views
1

当前我正在编辑的页面有一个JS菜单。这包含的项目如;使用javascript window.location更改端口

{ 
    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个地址)或Via web(具有公共IP)上访问,所以我不希望每次都必须设置域。

任何想法?

回答

1

设置了window.location与端口号的完整网址是:

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

如果您想使用当前的域,那么你可以使用window.location.hostname使用构造URL当前主机。

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

谢谢你的建议,但据说没有域被IP访问,可能是公共的或内部的,因此要迎合这两者。 – bighead85

+0

@ bighead85 - 查看我答案的第二部分。它应该使用当前的域名/ IP,无论使用哪一个。 – jfriend00

0

试图改变这样的

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

使用location.port = 80你的代码;在你的index.php这将工作

使用location.port = 80;将改变你目前的端口。

+0

这是我一直在尝试的事情,但由于某种原因,这不会改变请求中的端口。 – bighead85

+0

使用location.port = 80;在你的index.php文件中,只使用window.location ='index.php';重定向页面。 – Drone

+0

谢谢,不太清楚为什么,但仍然无法让我的网页工作。 (虽然这是我认为应该发生的事情)这可能与菜单的位置或某事有关,使用@ jfriend00这是行得通的。所以会坚持下去,谢谢你的建议。 – bighead85