Java, Javascript

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 Comments

  1. 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!!

Leave a Reply

Theme by Anders Norén

en_USEnglish
en_USEnglish
%d bloggers like this:
Skip to toolbar