The autofocus
property sets or gets
whether a URL field can automatically get focus when the page loads.
autofocus |
Yes | 10.0 | Yes | Yes | Yes |
Return the autofocus property.
var v = urlObject.autofocus
Set the autofocus property.
urlObject.autofocus=true|false
Value | Description |
---|---|
true|false | Set whether a URL field can get focus when the page loads
|
A Boolean type value, true if the URL field automatically gets focus when the page loads, otherwise false.
The following code shows how to check if a URL field can automatically get focus upon page load.
<!DOCTYPE html>
<html>
<body>
Homepage: <input type="url" id="myURL" autofocus>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- ww w.j a v a 2 s.com-->
var x = document.getElementById("myURL").autofocus;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: