The search
property sets or gets the
querystring part of the href attribute value.
The querystring used for parameter passing is the part of the URL after the question mark (?).
search |
Yes | Yes | Yes | Yes | Yes |
Return the search property:
var v = anchorObject.search;
Set the search property:
anchorObject.search = querystring;
Value | Description |
---|---|
querystring | Set the query string |
A String representing the querystring part of the URL.
The following code shows how to get the querystring part of a link.
<!DOCTYPE html>
<html>
<body>
<!--from w w w . j av a 2s. c om-->
<p><a id="myAnchor" href="http://www.example.com:80/test.htm?id=myPara">Example link</a></p>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myAnchor").search;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the querystring part of a link.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . j ava 2 s . c o m-->
<p><a id="myAnchor" target="_blank" href="http://www.example.com:80/test.htm?id=myPara">Example link</a></p>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myAnchor").search = "newValue";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows: