1

I'm using javascript and need to parse out a query argument that is a URL:

/folderone/two?link=http%3A%2F%2Fwww.cooldomainname.com

This is doubly hard because I not only need to parse out the query argument "link", but once I have that, the "://" seems to have been turned into: "%3A%2F%2F"

I got so far as to do this:

url.replace(/^.*\=/, '');

Which left me with:

http%3A%2F%2Fwww.cooldomainname.com

But now I still need to handle these "%3A%2F%2F" I could just do a find and replace, but I feel like there must be some type of library that I should be using to "de-URLify" query arguments?

1
  • please add a javascript tag Commented Apr 25, 2011 at 1:15

1 Answer 1

1

Use:

decodeURIComponent("http%3A%2F%2Fwww.cooldomainname.com");

Output:

"http://www.cooldomainname.com"

Note also that I think split is a more natural choice than replace:

"/folderone/two?link=http%3A%2F%2Fwww.cooldomainname.com".split("=")[1]

(It's assumed that your input string has just the one parameter.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.