Find out if a URL field automatically gets focus on page load:
var x = document.getElementById("myURL").autofocus;
Click the button to find out if the URL field automatically gets focus on page load.
elements with type="url" are not supported in Safari.
<!DOCTYPE html> <html> <body> Homepage: <input type="url" id="myURL" autofocus> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w. ja va 2 s . c o m var x = document.getElementById("myURL").autofocus; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The autofocus property sets or gets whether a URL field should automatically get focus on page load, or not.
This property mirrors the HTML autofocus attribute.
Value | Description |
---|---|
true | The URL field gets focus |
false | Default. The URL field does not get focus |
The autofocus property returns true if the URL field automatically gets focus on page load, otherwise it returns false.