I want to know what location.search.substring(1)
actually does. I saw this code on some website. I tried to print using alert
, but this did not give any result. Is it supposed to alert location href?
alert(location.search.substring(1))
The location object contains information about the current URL. The location object is a property of the window object. The location object is accessed with: window.location or just location.
The location. href property sets or returns the entire URL of the current page.
pathname. The pathname property of the Location interface is a string containing the path of the URL for the location, which will be the empty string if there is no path.
If javascript is enabled, window. location.search is safe to use.
http://example.com/index.php?foo=bar location.search > ?foo=bar location.search.substring(1) > foo=bar
So that code will return the entire query parameters without the question mark.
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