Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is location.search in javascript

Tags:

javascript

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)) 
like image 398
jchand Avatar asked Jan 18 '13 08:01

jchand


People also ask

What is location object in Javascript?

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.

What does location href do in Javascript?

The location. href property sets or returns the entire URL of the current page.

What is location pathname?

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.

Is Windows location search Safe?

If javascript is enabled, window. location.search is safe to use.


1 Answers

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.

like image 172
sachleen Avatar answered Sep 17 '22 09:09

sachleen