I have a url as string in javascript like follows :
I want to filter the string and get
?param=1¶m=2....
How can I do this in javascript?
I have a url as string in javascript like follows :
I want to filter the string and get
?param=1¶m=2....
How can I do this in javascript?
var str= "http://localhost:8080/Blah.ff?param=1¶m=2";
var str2 = str.substr(str.indexOf("?"), str.length);
alert(str2);
var str2 = str.substr(str.indexOf("?"));. Also, your solution assumes there is always a ? in the string.var urlstring = "http://localhost:8080/Blah.ff?param=1¶m=2";
var querystring = '?' + urlstring.split('?')[1];
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:
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.