2

If you go visit a YouTube video and then click another video ( e.g a related video ) you see that the page is not entirely refreshing, Only the main video and related videos change, The rest of the page remains as it is. I was wondering how they do that, If it's AJAX then why is the URL updating? I've seen this technique on some other famous websites too , I was wondering how this works?!

Amin
  • 1,637
  • 1
  • 22
  • 40
  • 2
    So your question isn't actually about AJAX, it's about how to modify the URL without loading a brand new page. See [Modify the URL without reloading the page](http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page). Voted to close this question as a duplicate of that one. – mason Nov 01 '15 at 16:35
  • It is about AJAX , because a part of page content , the page title , and the page URL gets modified, i don't know, It seems some sort of AJAX secret to me – Amin Nov 01 '15 at 16:38
  • 1
    You can modify page content, title, and URL entirely without AJAX. So it's not really about AJAX. AJAX is just one means of getting data from somewhere. Other sources of data might come from the user typing in data into a form, or web sockets, or HTML5 local storage, or cookies etc. So really, your question is not about AJAX. The page I linked to in my first comment describes how to change the URL, page content, and title. – mason Nov 01 '15 at 16:41
  • I think you're right mason , thank you <3 – Amin Nov 01 '15 at 16:42
  • 1
    I created an example [here](https://dl.dropboxusercontent.com/u/24662485/test.html) that doesn't involve AJAX, feel free to right click the page and view the source (hosted on my personal Dropbox). Keep in mind that the URL should always lead to the same application state, in case someone shares the URL. You don't want them to receive a 404 response or see something different than what the URL represented when they grabbed it. – mason Nov 01 '15 at 16:53
  • I checked it , thank you , i learned something new today from you! I really appreciate it :-) – Amin Nov 01 '15 at 17:07
  • @mason the URL is broken (the one hosted at dropbox) is there a way to reshare it? I have the same question as well. – chips May 25 '16 at 18:45
  • @chips I've long since deleted the page hosted at the URL. All it showed was a page that uses JavaScript to modify the URL, using techniques from the first comment I posted on this question. – mason May 25 '16 at 19:00

1 Answers1

1

You can change the URL without reloading the page, if the browser supports it.

Combined this with Ajax and you will see the behavior you are seeing.

Seabizkit
  • 2,417
  • 2
  • 15
  • 32