Truncate string in JavaScript
I have a url as string in javascript like follows :
http://localhos开发者_JS百科t:8080/Blah.ff?param=1¶m=2...
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);
http://jsfiddle.net/praveen_prasad/a9XBe/1/
var urlstring = "http://localhost:8080/Blah.ff?param=1¶m=2";
var querystring = '?' + urlstring.split('?')[1];
http://jsfiddle.net/ipr101/htUa3/
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/
精彩评论