Let's I have two server running on my PC. server1 and server2....
In a.html of server1 there is a tag. Now I want to access b.html from server2 by the above link that's why I have written
<a href="localhost:8080/b.html">
It's working really well if I access a.html and click that link working fine in my computer where both servers are running.
...... I want to access a.html from server1 in my phone. My pc and phone both are in the same wifi network.
To solve this problem I opened my phone browser and gave my pc ip ex. 192.168.0.1/a.html
It's working fine. But as I said in above that there is a link in that page (ex given above). When I click on that link it's giving error
This site can't be reached localhost refused to connect
.... I know where is the problem . The problem is in the link because I explicitly wrote localhost:8080 . Here is the problem. I should write my pc private it instead of localhost then it'll work I know. But how to get my private IP by javascript to modify the link dynamically by javascript.
Help me to solve this problem.
答案 0 :(得分:1)
您的手机基本上是重定向到自身。
您的<a>
标记应如下所示:
或者如果您不想弄乱HTML,那么这也是可能的<a href="192.168.0.1:8080/b.html">
<HTML5>
<head>
<base href="192.168.0.1:8080/">
</head>
<body>
<a href="b.html">b.html on server #2</a>
<br>
<a href="192.168.0.1/c.html">c.html on server #1</a>
</body>
</html>
答案 1 :(得分:1)
两台服务器都在您的电脑上运行。因此,要访问除自有PC之外的两台服务器,您需要提供私有IP。这样您就可以访问两台服务器。
现在,您首先要访问服务器1的a.html,其中有一个指向server.html的b.html的链接。
不要显式写 localhost 。 并且您想要动态更改链接的href。 在步骤下面。
<a id="link" href="#"></a>
<script>
window.onload=function()
{
//Modify the link href
var ip=location.host;
$("a#link").attr("href", "http://"+ip+":8080/b.html");
}
</script>