How to modify the URL without reloading the page

We can modify the URL of any site without but as soon as we modify it relods and navigates to the given URL page but there is a way to change the URL without reloading the page.

By the below example we can understand how we can modify the URL without without reloading the page.

function processAjaxData(response, urlPath){
     document.getElementById("content").innerHTML = response.html;
     document.title = response.pageTitle;
     window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
 }

window.onpopstate = function(e){
    if(e.state){
        document.getElementById("content").innerHTML = e.state.html;
        document.title = e.state.pageTitle;
    }
};

Leave a comment

Your email address will not be published. Required fields are marked *