I am not sure what to call this but in google plus, when you navigate to different pages, the HTTP address changes but the userbars seem to remain static and not reload. What is happening and how is this done?
I hope this makes sense! Thank you!
I am not sure what to call this but in google plus, when you navigate to different pages, the HTTP address changes but the userbars seem to remain static and not reload. What is happening and how is this done?
I hope this makes sense! Thank you!
The content is being loading asynchronously and the url in the address bar is being altered.
An basic example of loading content asynchronously:
$.ajax({
url: 'http://www.example.net/load.html',
dataType: 'html',
success: function(data){
// This will replace all content in the body tag with what has been retrieved
$('body').html(data);
}
});
See here for the $.ajax()
documentation.
To change the url withour redirecting, you need to use the HTML5 history API. A similar question has been asked here before, please see:
Modify the URL without reloading the page
Extracted answer:
function processAjaxData(response, urlPath){
document.getElementById("content").innerHTML = response.html;
document.title = response.pageTitle;
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
}
For more information on the HTML5 History API, please see here.
It's likely that they're using the HTML5 History API, specifically the pushState
method to add new history states. They're also probably using Ajax (XHR) to load in new content and then adding that content to the page via the DOM API.
Check out pjax, a library that takes care of most of this for you.