Window location.search attribute

Definition and usage

search The attribute returns the query string part of the URL, including the question mark (?).

search The attribute can also be used to set the query string.

Comment

The query string part is the part after the question mark (?) in the URL.

Query strings are used to pass parameters.

Example

Return the query string part of the URL:

let query = location.search;

Try it yourself

Syntax

Return search attribute:

location.search

Set search attribute:

location.search = querystring

Attribute value

Value Description
querystring The query string part of the URL.

Return value

Type Description
String

The query string part of the URL, including the question mark (?).

Browser Support

All Browsers Support location.search:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support