I'm trying to get the query string from a string (not the current URL).
For example, I have a URL 'www.google.com/?query=string', I'd like to be able to run a function on it and get '?query=string' back from it. How would I go about doing this?
Thanks
Well, you can use a quick regexp that gets you the part you need:
myString.match(/(\?.*)/)[1]
Example:
'www.google.com/?query=string'.match(/(\?.*)/)[1] // evaluates to '?query=string'
Window.location.search will evaluate to this.
http://www.w3schools.com/jsref/prop_loc_search.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With