Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove url parameters with javascript or jquery

I am trying to use the youtube data api to generate a video playlist.

However, the video urls require a format of:

youtube.com/watch?v=3sZOD3xKL0Y 

but what the api generates is:

youtube.com/watch?v=3sZOD3xKL0Y&feature=youtube_gdata 

So what I need to do is be able to select everything after and including the ampersand(&) and remove it from the url.

Any way to do this with javascript and some sort of regular expression?

like image 987
mheavers Avatar asked Jan 10 '11 21:01

mheavers


People also ask

How do I remove values from a 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);

Can you use Javascript to get URL parameter values?

The short answer is yes Javascript can parse URL parameter values. You can do this by leveraging URL Parameters to: Pass values from one page to another using the Javascript Get Method. Pass custom values to Google Analytics using the Google Tag Manager URL Variable which works the same as using a Javascript function.


1 Answers

What am I missing?

Why not:

url.split('?')[0]  
like image 114
goldylucks Avatar answered Sep 22 '22 00:09

goldylucks