How to Remove Query String from URL using JQuery?

By Hardik Savani January 31, 2023 Category : jQuery

Hey Artisan,

Now, let's see post of how to remove query string from URl. It's a simple example of remove query string using jquery code. I explained simply about example for remove query string. We will look at an example of hide query string. follow the below step for hide query string example.

Why remove query strings?

Main two reasons for this.

1. Clear URL alwaya look better than the long URL

2. When you are not remove your query string from URL. then all get variable show in you URL string. sometime it not good for a security

You can remove your query string using this simple Jquery code.

Example Code:

<!DOCTYPE html>



<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">




<script type="text/javascript">


var uri = window.location.toString();

if (uri.indexOf("?") > 0) {

var clean_uri = uri.substring(0, uri.indexOf("?"));

window.history.replaceState({}, document.title, clean_uri);






I hope it can help you...

Tags :