javascript - Comment modifier l'URL sans recharger la page

Mots clés : javascripthtmlurlurl-rewritingfriendly-urljavascript

meilleur 4 Réponses javascript - Comment modifier l'URL sans recharger la page

vote vote

97

 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 = function(e){     if(e.state){         document.getElementById("content").innerHTML = e.state.html;         document.title = e.state.pageTitle;     } }; 
vote vote

88

window.history.pushState('page2', 'Title', '/page2.php'); 
vote vote

71

if (window.history.replaceState) {    //prevents browser from storing history with each change:    window.history.replaceState(statedata, title, url); } 
vote vote

66

history.pushState({}, null, newUrl); 

Questions similaires