TechieHints SOFTWARE

How to change url without reloading the page

if (history.pushState) {

var newurl = window.location.protocol + "//" + window.location.host +                  window.location.pathname + '?queryParam1=paramValue1' ;
                                                        window.history.pushState({path:newurl},'',newurl);

}

Above snippet does the trick for you, It will change the url but not does the action.

Enclose with the javascript function copy paste the function in JS.

call the below function where ever required. ex:

                 pushQueryParam ( “param1=value1&param2=value2&param3=value3” );

function pushQueryParam ( queryParams ){

if (history.pushState) {

   var newurl = window.location.protocol + "//" + window.location.host +
             window.location.pathname + '?' + queryParams;
             
   window.history.pushState({path:newurl},'',newurl);

  }
}

2 responses to “How to change url without reloading the page”

  1. Heriberto Avatar

    Great web site you’ve got here.. It’s difficult to find excellent
    writing like yours nowadays. I seriously appreciate people like you!
    Take care!!

    1. Sandeep Avatar

      Thank you. Heriberto for the comment.

Leave a comment