ItSolutionStuff.com

How to Remove Query String from URL using JQuery?

By Hardik Savani • January 31, 2023
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>

<html>

<head>

<meta charset="utf-8">

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

<title></title>

</head>

<body>

<script type="text/javascript">

$(document).ready(function(){

var uri = window.location.toString();

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

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

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

}

});

</script>

</body>

</html>

I hope it can help you...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel JQuery UI Autocomplete Ajax Search Example

Read Now →

How to Remove Last Element from Array in JQuery?

Read Now →

JQuery Moment Get Current Date Example

Read Now →

JQuery Remove Parent Table Row on Button Click Event

Read Now →

JQuery Toggle Hide Show Div on Click Event Example

Read Now →

Add Edit Delete Table Row Example using JQuery

Read Now →

How to Disable Browser Back Button using JQuery?

Read Now →

JQuery Rotate Image Animation Example Code

Read Now →

JQuery - How to Push Specific Key and Value in Array?

Read Now →

Laravel 11 JQuery Ajax Pagination Example

Read Now →

How to Get the Current URL using JQuery?

Read Now →

How to Convert Line Breaks to br in jQuery ?

Read Now →