How to remove query string parameter using jQuery

No comments
In this article we will talk about How to remove query string parameters using jQuery. First of all, we will understand why we use query string in a URL. We use query string in a URL to get required parameter value to execute in the current loaded page or to track the source of direction. However; URLs with lots of query strings looks ugly, a normal visitor cannot memorize that and now days search engines are also not preferring this technique also is more secure.


So, here is the code that will help you in removing this dirty query strings from your page URL:
<script type="text/javascript">
$(document).ready(function(){
    if (window.location.href.indexOf('?') > -1) {
        history.pushState('', document.title, window.location.pathname);
    }
});
</script>

Please note that, above code will remove the query strings from the page URL and the page will not be reloaded and some functionalities running on the page can be stopped. I recommend you before using this code, please check this code is not affecting running functionalities on your page/module etc.

Please feel free to share your feedback in the comment box below or if you have any question, you can ask too. Best regards, Akhilesh 

No comments :

Post a Comment