gpt4 book ai didi

javascript - 使用 Javascript 将 URL 中的域名大写

转载 作者:行者123 更新时间:2023-11-30 13:14:33 24 4
gpt4 key购买 nike

看看下面的代码:

<!--begin of index.html-->

<a href="#" id='click'>Click to change url to Index2.html</a>

<script type="text/javascript">
var stateObj = { foo: "bar" };
function change_my_url()
{
history.pushState(stateObj, "page 2", "http://MyDomain.com/Index2.html");
}
var link = document.getElementById('click');
link.addEventListener('click', change_my_url, false);
</script>

<!--end of index.html-->

这是在不重新加载页面的情况下更改 URL 的示例脚本。

脚本成功更新来自 http://mydomain.com/index.html 的 URL http://mydomain.com/Index2.html 无需重新加载页面。但是,尽管在更新的 URL 中,文件名如代码中所述是大写的,但域名不是大写的。我希望 URL 看起来像 http://MyDomain.com/Index2.html . 这可能吗?

我知道我认为此脚本会将域名大写的假设是错误的。但我只是给了你一个我努力的例子Capitalizing a domain name in a URL using Javascript.

最佳答案

域名不区分大小写,但惯例是只使用小写。这就是为什么您的浏览器总是将您提供的域名改写为大写字母的小写形式。如果没有这个约定,我们会有不同的字符串作为相同的 URL,这会造成混淆。

关于javascript - 使用 Javascript 将 URL 中的域名大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12551517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com