1

I'm using the following code to change the URL of a page without reloading the whole page:

 alert( window.location.href ); 
 window.history.pushState( {} , 'foo', '/foo' );
 alert( window.location.href ); 

Result:

First alert:

file:///C:/Users/name/Desktop/html/first.html

Second alert:
No Alert and no change in URL but I was expecting following:

file:///C:/Users/name/Desktop/html/foo

Where's the glitch? And how to change the browser URL without reloading the page?

Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
Sowmay Jain
  • 865
  • 1
  • 10
  • 21
  • 4
    Possible duplicate of [history.pushState will not work](http://stackoverflow.com/questions/39814218/history-pushstate-will-not-work) – JJJ Feb 23 '17 at 07:22

1 Answers1

2

Don't run this command using the physical files. It should be hosted on a real domain or localhost.

Examples:

http://localhost/first.html

http://www.example.com/first.html

Amir H. Bagheri
  • 1,416
  • 1
  • 9
  • 17