0

now i am learning about History API modules of Javascript. Sorry for the stupid question but after i tried to read the information from web, i still can not have a very clear concept...

What is the advantages of this API and is it different between AJAX? How can we apply this api in the real applications?

Some website said that you can change the url without re-load the page! and from the w3c..

The history object contains the URLs visited by the user (within a browser window).

The history object is part of the window object and is accessed through the window.history property.

Thanks!

Sebastian Simon
  • 14,320
  • 6
  • 42
  • 61
chw
  • 11
  • 2
  • *"What is the advantages of this API and is it different between AJAX?"* uh? It's like asking how is the AJAX API different from WebGL. They are completely different things, you can't compare them. – Federico klez Culloca Jul 12 '18 at 15:34
  • 2
    You were reading the documentation on [W3Schools](https://www.w3schools.com/jsref/obj_history.asp). Read the better [History API docs on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/history). The [W3C docs are here](https://www.w3.org/TR/2011/WD-html5-20110113/history.html). W3C and W3Schools are not the same thing. – Sebastian Simon Jul 12 '18 at 15:35
  • Dear thanks for you comment and because while I see it can update the URL and JavaScript without F5 operation ... – chw Jul 12 '18 at 15:44
  • A couple of other hints: you were using the wrong tag for the question. The History API is not a library. Read the tag description excerpts, and read the [full description](https://stackoverflow.com/tags/html5-history/info), as these contain more information and links that may answer questions like these. Also, you might want to read about the [`History` object](https://developer.mozilla.org/en-US/docs/Web/API/History) that `window.history` returns, as this is the interface that contains the most useful methods like `replaceState` and `pushState`. – Sebastian Simon Jul 12 '18 at 15:45
  • 1
    Dear Sir , thanks for you suggestion and I will read the doc clearly again!:) sorry for my stupid question. – chw Jul 12 '18 at 15:46
  • Dear Sir, Thanks for you reply and now i have a basic concept of this API. but would you give me some idea how apply it in the real applications? Thanks! – chw Jul 18 '18 at 13:53

1 Answers1

1

AJAX stands for Asynchronous JavaScript and XML. Essentially, what AJAX does is performs tasks such as making data requests or updating parts of your webpage without reloading the entire webpage (just the parts you specified).

API stands for Application Programming Interface. APIs allow your program some sort of special information or data. In this case you are using the History API which grants you the ability to see and performs certain actions with the history (the previously visited webpages) of your browser in your current session.

A real world use for the History API would be using the History.scrollRestoration property. When a user navigates back to a previously visited webpage that is saved in the browser's history it will also scroll the webpage down the to last place the user was before leaving that webpage. That is an example of how the History API can improve the UX (User Experience).