3

I want to change the url in browser bar without reloading page.

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

When any user enter my website like www.a-site.com After open this site he see the text Refresh page to see our other website. Can I do that when he enter in www.a-site.com, after this url change in browser bar like www.b-site.com and when user refresh page it can automaticaaly redirect in
www.b-site.com. can this is possible.
Thanks...............

Axeem
  • 670
  • 4
  • 16
  • 26

1 Answers1

11

You are looking for following

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

Here is the original article I read (posted July 10, 2012): HTML5: Changing the browser-URL without refreshing page.

Example:

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

Documentation

underscore
  • 6,495
  • 6
  • 39
  • 78