-2

I have a url as string in javascript like follows :

http://localhost:8080/Blah.ff?param=1&param=2...

I want to filter the string and get

?param=1&param=2....

How can I do this in javascript?

1

3 Answers 3

4
var str= "http://localhost:8080/Blah.ff?param=1&param=2";
var str2 = str.substr(str.indexOf("?"), str.length);
alert(str2);

http://jsfiddle.net/praveen_prasad/a9XBe/1/

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

1 Comment

The second line of this can be simplified to: var str2 = str.substr(str.indexOf("?"));. Also, your solution assumes there is always a ? in the string.
2
var urlstring = "http://localhost:8080/Blah.ff?param=1&param=2";
var querystring = '?' + urlstring.split('?')[1];

http://jsfiddle.net/ipr101/htUa3/

Comments

-2

There are a lot of ways to do this. I would start with the window.location or location.href elements. Read up some more here:

http://www.w3schools.com/js/

2 Comments

@kingjiv You know I read all the criticism on that page, and all of it was stupid nitpicking. All the real stuff was fixed by w3schools as soon as that page went up. So maybe there was a good reason for it once, but not anymore.
@ariel some have been cleaned up, but there are still some bad ones. Since the link was to js. The first on the list for js is pretty bad. They only show that you can pass a string to setTimeout (which uses eval) and don't show how you can (and should) pass a function. It may be better than it was, but there are still issues. Even when they do create a function, they call it in a string. They promote bad practices.

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.