Javascript Reference - HTML DOM Keygen Object








The Keygen object represents an HTML <keygen> element.

Example

We can access a <keygen> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<!--from   w  w w  .j av  a 2s.  co  m-->

<keygen id="myKeygen" name="security">

<p>Click the button to disable the keygen field.</p>

<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    var x = document.getElementById("myKeygen");
    x.disabled = true;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create a <keygen> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<!--from  w w w. j  ava2 s .com-->
<p>Click the button to create a KEYGEN element.</p>

<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    var x = document.createElement("KEYGEN");
    x.setAttribute("name", "security");
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows:





Keygen Object Properties

Property Description
autofocus Sets or gets whether a keygen field can auto focus when the page loads
challenge Sets or gets the challenge attribute of a keygen field
disabled Disable or enable a keygen field
form Get the form that contains the keygen field
keytype Sets or gets the keytype attribute of a keygen field
name Sets or gets the name attribute of a keygen field
type Get the type string of the keygen field

Standard Properties and Events

The Keygen object supports the standard properties and events.