在不重新加载页面的情况下更改浏览器栏中的 URL

Change the url in browser bar without reloading page

本文关键字:情况下 浏览器 URL 新加载 加载      更新时间:2023-09-26

我想在不重新加载页面的情况下更改浏览器栏中的网址。

<html><head>
 <title>Change url in browser bar</title>
</head>
     <body>
             <h1>Refresh page to see our other website</h1>
     </body>
 </html>

当任何用户进入我的网站时,如 www.a-site.com 打开此网站后,他会看到文本刷新页面以查看我们的其他网站。当他输入 www.a-site.com 时,在浏览器栏中(如 www.b-site.com)更改此 url 以及当用户刷新页面
时,我可以这样做吗? www.b-site.com。这可能吗?
谢谢。。。。。。。。。。。。。。。

您正在寻找以下内容

window.history.pushState("object or string", "Title", "/new-url");

以下是我阅读的原始文章(发表于2012年7月10日):HTML5:在不刷新页面的情况下更改浏览器URL。

例:

 function processAjaxData(response, urlPath){
     document.getElementById("content").innerHTML = response.html;
     document.title = response.pageTitle;
     window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
 }

文档

相关文章: