Removing Querystring From Current Page Url In Javascript
I want to remove querystring from my current page url in javascript on button Click can u pls help me with the above code.
Solution 1:
try
var query = window.location.href.match(/^(.*)\?/);
if (query){
history.pushState(null, "", query[1]);
}
Solution 2:
You cant simple remove query string without redirection or reloading the page . So u will be changing the location or redirecting by using windows.location . getPathFromUrl() function remove the query-string from given URL.
Here is example how can u do it :
functiongetPathFromUrl(url) {
return url.split("?")[0];
}
var testurl='http://localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx?date=20-Sep-2012%22'window.location=getPathFromUrl(testurl); // loads http://localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx
Solution 3:
Here, try this:
window.location = String(window.location).match(/(.*?)\?/)[1];
Or using the example URL in the comments
window.location = "http://localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx?date=20-Sep-2012%22".match(/(.*?)\?/)[1];
Solution 4:
You can just trim the whole string succeeding the "?" sign
Post a Comment for "Removing Querystring From Current Page Url In Javascript"