English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Location search attribute

JavaScript Location Object

searchSet or return the attributeQuery stringof the URL, including the question mark part (?).

querystringPart is the part after the question mark (?) in the URL. This is usually used for parameter passing.

Syntax:

Return the search attribute:

location.search

Set the search attribute:

location.search = querystring
var x = location.search;
document.querySelector("#output").innerHTML = x;
Test and See‹/›

Browser compatibility

All browsers fully support the search attribute:

Attribute
searchIsIsIsIsIs

Attribute value

ValueDescription
querystringA string that specifies the search part of the URL

Technical details

Return value:A string representing the querystring part of the URL, including the question mark (?)

More examples

This example shows all position properties:

var txt = "";
txt += "<p>Host: " + location.host + "</p>";
txt += "<p>Hostname: " + location.hostname + "</p>";
txt += "<p>Href: " + location.href + "</p>";
txt += "<p>Origin: " + location.origin + "</p>";
txt += "<p>Pathname: " + location.pathname + "</p>";
txt += "<p>Protocol: " + location.protocol + "</p>";
txt += "<p>Search: " + location.search + "</p>";
document.write(txt);
Test and See‹/›

Related References

Location Reference:location.pathname property

Location Reference:location.host property

Location Reference:location.href property

Location Reference:location.hash property

JavaScript Location Object