matt
matt

Reputation: 44293

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. $goToURL = 'http://www.anydomain.com/hello/?path=xyz how can i get ?path=xyz out there and save it to a variable?

regards matt

Upvotes: 0

Views: 299

Answers (2)

karim79
karim79

Reputation: 342625

[edited based on @Nick's comment]

alert('http://www.anydomain.com/hello/?path=xyz'.split('?', 1)[1]);

Upvotes: 2

Gareth
Gareth

Reputation: 138002

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)

Upvotes: 2

Related Questions