Remove Part Of Url With Jquery
How would I remove part of a URL with jQuery, when the said part is changeable? E.g. how can I remove this from my URL: ?modal=name when 'name' might be name1 name2 or name3 I gues
Solution 1:
var url = 'http://yourdomain.com/search?modal=name';
alert(url.substring(0, url.indexOf('?')));
Solution 2:
As you have asked "How to remove the part of a URL" using jQuery
Here is a basic workaround for you:
//the URL ( decode it just for GOOD practice)var someRandomUrl = decodeURI("http://example.com?modal=name");
//here we do the splittingvar splittedParts = someRandomUrl.split("?");
// the first part of the array will be URL you will requirevar theURL = splittedParts[0];
// the second part of the array will be the Query Stringvar theQuery = splittedParts[1];
alert(theURL);
Post a Comment for "Remove Part Of Url With Jquery"