Skip to content Skip to sidebar Skip to footer

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('?')));

Demo


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 splitting
var splittedParts = someRandomUrl.split("?");

// the first part of the array will be URL you will require
var theURL = splittedParts[0];

// the second part of the array will be the Query String
var theQuery = splittedParts[1];
alert(theURL);

Post a Comment for "Remove Part Of URL With JQuery"