Hello Guys
Here, We can update address bar with new URL without hash or reloading the page by using javascript.
Following examples help you to better understanding :
function processAjaxData(response, urlPath){
document.getElementById("content").innerHTML = response.html;
document.title = response.pageTitle;
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
}
You use window.onpopstate to detect the back/forward navigation:
window.onpopstate = function(e){
if(e.state){
document.getElementById("content").innerHTML = e.state.html;
document.title = e.state.pageTitle;
}
};
You can use below example for HTML5 and before :
if (window.history.replaceState) {
//prevents browser from storing history with each change
window.history.replaceState(statedata, title, url);
}
Before HTML5 you can use following example:
parent.location.hash = "hello";
and:
window.location.replace("http:www.example.com");
0 Comment(s)