Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Query String from URL by using jquery (working with issue)

In my website blog pages added query string in that page URL. I wanted to remove the query string from the URL. So i used to go with jquery and i wrote and added into my scripts. It removes the query string but keep on refreshing the page upto nth time. I used to "one" jquery method. That also doesn't work.

Can you help me

My Script is

jQuery(document).one('ready',function(){
    window.location.href = window.location.href.split('?')[0];
});
like image 980
Bhavan Kumar Natarajan Avatar asked Mar 31 '16 07:03

Bhavan Kumar Natarajan


People also ask

How do I remove Querystring from URL?

To remove a querystring from a url, use the split() method to split the string on a question mark and access the array element at index 0 , e.g. url. split('? ')[0] . The split method will return an array containing 2 substrings, where the first element is the url before the querystring.

How do I clear URLSearchParams?

delete() The delete() method of the URLSearchParams interface deletes the given search parameter and all its associated values, from the list of all search parameters.

Why remove query string from url?

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

How to remove query strings from URL with W3 total cache?

W3 Total Cache plugin offers an option to remove query strings from static resources. You only need to UNCHECK (if already checked) an option and it will remove query strings from 90% of the URLs. Steps to Remove Query Strings from URL with WordPress plugin Install and Activate the W3 Total Cache Plugin.

How to remove query strings from static resources?

Query Strings can be removed by using a WordPress plugin called Remove Query Strings From Static Resources. I would recommend this method to beginners, who don’t want to mess up with coding stuff. Install and activate this plugin. There is no setting panel, so just activation of the plugin will do the trick.

What are query string resources?

Query Strings are the URLs that contain “?” or “&”. for example, technumero.com/script.js?ver=1.6 It is similar to the CSS and JS files of your website, which usually have the file version at the end of their URLs. Therefore, these query string resources would be the resource URLs with a “?” or “&”.


1 Answers

var uri = window.location.href.toString();
if (uri.indexOf("?") > 0) {
    var clean_uri = uri.substring(0, uri.indexOf("?"));
    window.history.replaceState({}, document.title, clean_uri);
}
like image 117
bksoni Avatar answered Oct 18 '22 11:10

bksoni