Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Modify or change the URL without reloading the page using javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 275
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: