Set a URL field to read-only:
document.getElementById("myURL").readOnly = true;
Click the button to set the URL field to read-only.
elements with type="url" are not supported in Safari.
<!DOCTYPE html> <html> <body> Homepage: <input type="url" id="myURL"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*w w w . ja va2 s . co m*/ document.getElementById("myURL").readOnly = true; } </script> </body> </html>
The readOnly property sets or gets whether a URL field should be read-only.
A read-only field cannot be modified.
This property mirrors the HTML readonly attribute.
Value | Description |
---|---|
true | The URL field is read-only |
false | Default. The URL field is not read-only |
The readOnly property returns true if the URL field is read-only, otherwise it returns false.