How to Remove Query String from URL using 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel JQuery UI Autocomplete Ajax Search Example
- How to Remove Last Element from Array in JQuery?
- JQuery Moment Get Current Date Example
- JQuery Remove Parent Table Row on Button Click Event
- JQuery Toggle Hide Show Div on Click Event Example
- Add Edit Delete Table Row Example using JQuery
- How to Disable Browser Back Button using JQuery?
- JQuery Rotate Image Animation Example Code
- JQuery - How to Push Specific Key and Value in Array?
- Laravel 11 JQuery Ajax Pagination Example
- How to Get the Current URL using JQuery?
- How to Convert Line Breaks to br in jQuery ?