The autofocus
property sets or gets
whether a keygen field can auto focus when the page loads, or not.
autofocus |
Yes | No | Yes | Yes | Yes |
Return the autofocus property.
var v = keygenObject.autofocus
Set the autofocus property.
keygenObject.autofocus=true|false
Value | Description |
---|---|
true|false | Set whether a keygen field can auto focus when the page loads
|
A Boolean type value, true if the keygen field automatically gets focus when the page loads, otherwise false.
The following code shows how to create a <keygen> element and set autofocus to "true".
<!DOCTYPE html>
<html>
<body>
<!--from w w w . ja v a2 s . c o m-->
<button onclick="myFunction()">autofocus</button>
<button onclick="myFunction2()"No autofocus</button>
<br>
<script>
function myFunction() {
var x = document.createElement("KEYGEN");
x.setAttribute("autofocus", "autofocus");
document.body.appendChild(x);
}
function myFunction2() {
var y = document.createElement("KEYGEN");
document.body.appendChild(y);
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to check if a keygen field can auto focus upon page load.
<!DOCTYPE html>
<html>
<body>
<!--from w w w . j a va 2 s. c o m-->
Encryption: <keygen id="myKeygen" name="security" autofocus>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myKeygen").autofocus;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: