3

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

<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时,我可以这样做吗,在浏览器栏中更改此 URL 后,如www.b-site.com并且当用户刷新页面时,它可以自动重定向到
www.b-site.com。这可以吗。
谢谢...............

4

1 回答 1

11

您正在寻找以下

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);
 }

文档

于 2013-10-05T02:39:47.393 回答