Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery removing everything after question mark in url

I was wondering if I can remove everything after a question mark in a URL?

http://www.site.com?some_parameters_continue_forever

can I just use .remove()? What would need to be put inside the parameters?

Thanks

like image 289
hellomello Avatar asked Jul 16 '12 06:07

hellomello


People also ask

How to remove querystring from url in javascript?

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 to remove parameter from url?

Just pass in the param you want to remove from the URL and the original URL value, and the function will strip it out for you. To use it, simply do something like this: var originalURL = "http://yourewebsite.com?id=10&color_id=1"; var alteredURL = removeParam("color_id", originalURL);

What is after question mark in URL?

Its name is query string. After the question mark you can pass key-value pairs and use them server-side.


1 Answers

Since the url is controlled by the browser when you change the url the page will reload. Still for what you want to do, on pages where you don't need the stuff after the ? mark type..

window.location = "http://www.mysite.com" //or whatever your site url is

To dynamically do this you can use the below function and then use window.location

function getPathFromUrl(url) {
  return url.split("?")[0];
}

Note: When you change the url the page will refresh.

like image 53
LoneWOLFs Avatar answered Dec 01 '22 01:12

LoneWOLFs