js如何在不重新加载页面的情况下修改 URL?

有没有办法可以在不重新加载页面的情况下修改当前页面的 URL?
如果可能,我想访问# 哈希之前的部分。
我只需要更改域之后的部分,所以我不违反跨域策略。
window.location.href = "http://www.mysite.com/page2.php%22; // Sadly this reloads


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

//然后,您可以使用window.onpopstate来检测后退/前进按钮导航:

window.onpopstate = function(e){
    if(e.state){
        document.getElementById("content").innerHTML = e.state.html;
        document.title = e.state.pageTitle;
    }
};