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?
Don't run this command using the physical files. It should be hosted on a real domain or localhost.
Examples:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.