javascripthtmljquery.htaccess

How to change the page url without reloading the page


I want to know how can I change the page URL without reloading the page or changing the page content. I already use that code (JavaScript):

if(history.pushState){
  window.history.pushState("object or string", "Title", "/");
}else{
  document.location.href = "/";
}

But it doen't work in all browsers and Firefox marks it as insecure. Is there other ways to do what I want in JavaScript/jQuery/.htaccess/HTML meta tags

I want an answer that doesn't use window.history.pushState

Those answers don't help:


Solution

  • You can use HTML5 replaceState if you want to change the url but don't want to append this entry to the browser history:

    if(window.history.replaceState){
       window.history.replaceState(STATEDATA, TITLE, URL);
    }