window.location.search
Summary
The search property contains the query string portion of the current url.
Property of apis/locationapis/location
Syntax
Note: This property is read-only.
var result = window.location.search;
Return Value
Returns an object of type StringString
The query string portion of the URL. This includes the question mark, and everything following, excluding the hash.
For example, http://example.org/?page=1&mode=b#foo
would return the query string ?page=1&mode=b
.
Examples
The following example assumes your document has a div element with id 'hostDiv’, like this.
// Get the query string from window.location
var hostqs = window.location.search;
// Get a div element with id 'hostDiv'
var container = document.getElementById('hostDiv');
// Fill in the div element with the query string
container.innerHTML = hostqs;
Related specifications
- Window Object 1.0
- W3C Working Draft