Is there a way to update the URL programatically without reloading the page?
EDIT: I added something in the title in post .I just want to make it clear that I don’t want to reload the page
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes –
document.location = "http://my.new.url.com"You can also retrieve it the same way eg.
The location object has a number of useful properties too:
EDIT:
Setting the hash of the document.location shouldn’t reload the page, just alter where on the page the focus is. So updating to
#myIdwill scroll to the element withid="myId". If theiddoesn’t exist I believe nothing will happen? (Need to confirm on various browsers though)EDIT2: To make it clear, not just in a comment:
You can’t update the whole URL with javascript without changing the page, this is a security restriction. Otherwise you could click on a link to a random page, crafted to look like gmail, and instantly change the URL to http://www.gmail.com and steal people’s login details.
You can change the part after the domain on some browsers to cope with AJAX style things, but that’s already been linked to by Osiris. What’s more, you probably shouldn’t do this, even if you could. The URL tells the user where he/she is on your site. If you change it without changing the page contents, it’s becomes a little confusing.