Javascript: getting location.search out of any url?
i know top.location.search retruns ?key=anything&blabla=foobar of my current url. I wonder how i can get the search value out of any url?
if I have e.g. 开发者_如何学JAVA $goToURL = 'http://www.anydomain.com/hello/?path=xyz how can i get ?path=xyz out there and save it to a variable?
regards matt
[edited based on @Nick's comment]
alert('http://www.anydomain.com/hello/?path=xyz'.split('?', 1)[1]);
The location properties like .search are also available on <a>
elements. So, create an <a>
element dynamically and set it's href, and you should be able to access those properties.
var a = document.createElement('a')
a.href = "..."
console.log(a.search)
精彩评论