简体   繁体   English

如何在地址栏中显示一个不同的地址?

[英]How can I make an address in the address bar appear differently?

I have a DNS, and each computer has a website to make different folders / documents accessible in a different way than just browsing to that computer. 我有一个DNS,每台计算机都有一个网站,可以通过不同的方式访问不同的文件夹/文档,而不仅仅是浏览到该计算机。 For example, \\Media takes me to the media servers pages (Music, Movies, etc.), and \\Aurora takes me to the media server's website. 例如,\\ Media带我到媒体服务器页面(音乐,电影等),\\ Aurora带我到媒体服务器的网站。 Instead of it displaying "Aurora" in the address bar, however, I would like to use a script to replace it with "Aurora - Media Server Website, (server information)." 但是,我希望使用脚本将其替换为“ Aurora-媒体服务器网站,(服务器信息)”,而不是在地址栏中显示“ Aurora”。 I would really like to learn this method, I tried to look somewhere and it mentioned JavaScript would probably be the easiest way to do this. 我真的很想学习这种方法,我试图去找一个地方,它提到JavaScript可能是最简单的方法。 This would be helpful if I actually knew JavaScript =p If there is an easier way to do this, that would also be much appreciated =] 如果我真的知道JavaScript = p,这将很有帮助= p如果有更简单的方法可以做到这一点,那将不胜感激=]

In a nutshell, I want the address of a website, //Aurora, hosted on a local DNS server to appear as "Aurora - Media Server Website (server information)." 简而言之,我希望托管在本地DNS服务器上的// Aurora网站的地址显示为“ Aurora-媒体服务器网站(服务器信息)”。 What would be a possible way to implement this? 有什么可能的方法来实现这一目标?

Just use the replaceState method of window.history in JavaScript like so: 只需在JavaScript中使用window.history的replaceState方法,如下所示:

window.history.replaceState({}, '', url);

(params are: data (object), title (string), url (string)); (参数为:数据(对象),标题(字符串),网址(字符串));

I do it all the time to modify the URL, to remove the query string when using AJAX. 我一直在修改URL,使用AJAX时删除查询字符串。

If you want to change the hostname then you have to change the DNS so that the machine gets the name you want. 如果要更改主机名,则必须更改DNS,以便计算机获得所需的名称。 You can't use spaces or parenthesis in hostnames though. 但是,您不能在主机名中使用空格或括号。

The closest you can come with JS is the history API which only lets you modify the local part of the URI. 与JS一起提供的最接近的是History API ,它仅允许您修改URI的本地部分。

It is not possible to change the contents of the address bar due to security reasons (Phishing websites would exploit this heavily). 由于安全原因,无法更改地址栏的内容(网络钓鱼网站会大量利用此地址)。

I would suggest simply changing the title of the page. 我建议仅更改页面标题。

<title>Title goes here</title>

If you want to change it using javascript (for some reason) you can do this: 如果您想使用javascript进行更改(出于某种原因),可以执行以下操作:

document.title = "The new title goes here.";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM