Thursday, October 3, 2019

Change url query string value using jQuery

var url="http://www.test.com/admin/userSearch.aspx?FS=oldvalue";
var ReplaceNewValue="NewValue";
 var _fs = window.location.href.match(/FS\=([a-z0-9]+)/i);

                if (_fs != null) {
                    var value = window.location.href.substring(window.location.href.lastIndexOf('FS')); 
                    window.location = window.location.href.replace(value, 'FS=' +ReplaceNewValue + '');

                }

Result :  
   "http://www.test.com/admin/userSearch.aspx?FS=NewValue";

No comments:

Post a Comment