Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change url via JavaScript (no hash-tag)

I'm wondering how does facebook change the url when I switch between pictures in a album? There is no hash-tag, just a real url.

Example: The current url: facebook.com/photo.php?fbid=XXXXXX1 and if I click next, the url changes to facebook.com/photo.php?fbid=XXXXXX2

Does anybody know how to realize this with JavaScript?

like image 966
daniel Avatar asked Nov 07 '10 00:11

daniel


People also ask

Can we change URL using JavaScript?

location to Redirect to a Different URL with JavaScript. You can redirect a web page to another page in a number of ways including server-side redirects, HTML meta refresh redirects and JavaScript redirects.

How do I remove a hash from a link?

To remove the hash URL, use the history API's replaceState method to remove the hash location.

How do I change the URL of a website without reloading it?

The pushState() method is used to pass the properties in the form of parameters to add the new history entry. It is used to modify the current URL with the new given state without having to reload the page. It has three parameters: data : This is the object to store data related to URL.

How do you edit a link in JavaScript?

Use the textContent property to change the text of a link element, e.g. link. textContent = 'Replacement link text' . The textContent property will set the text of the link to the provided string, replacing any of the existing content.


2 Answers

Yes. Check out https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries

It pushes a new history state (an HTML5 thing) instead of using the hash key.

like image 163
Matthew Brown Avatar answered Sep 27 '22 20:09

Matthew Brown


My first hunch would be:

document.location = facebook.com/photo.php?fbid=XXXXXX2;

With some way of preventing the default reload page action.

like image 35
Jeremy Worboys Avatar answered Sep 27 '22 19:09

Jeremy Worboys