I'll answer point by point about the history part. As for getJSON
, I think it's the case for a separate question, as I said in the above comment (do not get mean, we're crazy for organization here on the site, ideally the questions should be focused so they can help to other people).
Is there a difference between window.history.pushState
or only history.pushState
?
No. In browsers, window
is the global object. Everything that hangs in window
can be accessed with or without window.
.
What is the function of the first attribute (in this case "null") window.history.pushState(null, "titulo", "novaurl")
?
This is one of the most interesting things about the History API. You can pass an object that represents the state of the application at that particular moment. When the person returns to that point (via browser's back button, for example), a popstate
event is triggered, and the listener of that event receives the corresponding state object. So you can restore the application state without having to fetch data from the server.
The object to be passed must be a simple object that can be serialized (that is, without functions / methods, and I would also avoid inherited content via prototype). The serialized object should occupy a maximum of 640k characters.
The second attribute, responsible for the new title, does not work. Proceed with document.title = "novoTitulo"
is the correct form?
The purpose of the second argument for pushState
is not to change the page title, but to save a title in the history. If you want to change the current title, you actually need to use document.title = "novoTitulo"
.
Is there any incompatibility of the 'window.history.pushState () function with IE?
Yes, from what I know it's only available from IE10.
I've seen in Github a library called History.js. For what does it serve since the history function is already native to browsers (I'm asking why I really could not understand)?
The purpose is to offer something close to the official API in a browser where it is not supported, such as versions of IE prior to 10. The library uses fallback mechanisms such as hashes to handle states and URL exchanges.
Relevant documentation: