Url.search (Property)

The query portion of an HREF URL if there is one.

Availability:

JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape version - 2.0
Opera browser - 3.0
Property/method value type:String primitive
JavaScript syntax:-myUrl.search
-myUrl.search = aString
HTML syntax:<A HREF="..."> <LINK HREF="...">
Argument list:aStringA new search string.

This property yields a text string that contains the query value from the URL if there is one and an empty string if not.

This should really be called the query portion of the URL instead of the search attribute.

You can assign a new value to this property. This might be useful if the user needs to specify some search parameters, which can be range checked at the client end. You will need to prefix the new value with a question mark otherwise the assignment won't work.

It is probably named 'search' due to it having been used by search engines, and that being the way people first noticed its widespread use when inspecting their web server's referrer logs.

Example code:

   <HTML>
   <HEAD>
   </HEAD>
   <BODY>
   <A NAME="EXAMPLE" HREF="http://www.mydomain.com:8080/folder/file.html#abcdef">Click here</A><BR>
   <SCRIPT>
   // In testing, this did not work in Opera 5.0
   document.write(document.links[0].search);
   </SCRIPT>
   </BODY>
   </HTML>

See also:Anchor.hash, Anchor.search, request.<urlExtension>, URL, Url object, Url.hash, Url.host, Url.hostname, Url.href, Url.pathname, Url.port, Url.protocol, Url.target