
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM write() Method
The HTML DOM write() provides user the functionality to write multiple expressions (HTML or JavaScript) directly to a document.
NOTE − This method overwrites HTML code in a document, if any and does not appends arguments to a new line.
Syntax
Following is the syntax −
document.write(arguments)
Example
Let us see an example of HTML DOM document write() method −
<!DOCTYPE html> <html> <head> <title>HTML DOM write()</title> <style> * { padding: 2px; margin:5px; } form { width:70%; margin: 0 auto; text-align: center; } input[type="button"] { border-radius: 10px; </style> </head> <body> <form> <fieldset> <legend>HTML-DOM-write( )</legend> <input id="urlSelect" type="url" placeholder="Type URL here..."><br> <input id="textSelect" type="text" placeholder="Full Name"><br> <input type="button" value="Go To" onclick="openWindow()"> <input type="button" value="Close" onclick="closeWindow()"> <input type="button" value="Restore" onclick="restoreWindow()"> <div id="divDisplay"></div> </fieldset> </form> <script> var urlSelect = document.getElementById("urlSelect"); var textSelect = document.getElementById("textSelect"); var winSource; function openWindow() { browseWindow = window.open(urlSelect.value, "browseWindow", "width=400, height=200"); winSource = urlSelect.value; browseWindow.opener.document.getElementById("divDisplay").textContent = "Child Window Active"; if(textSelect.value !== 'admin') browseWindow.document.write("<p><strong>Unauthorized User: </strong></p>","<p>"+textSelect.value+"</p>"); } function closeWindow(){ if(browseWindow){ browseWindow.close(); browseWindow.opener.document.getElementById("divDisplay").textContent = "Child Window Closed"; } } function restoreWindow(){ if(browseWindow.closed){ browseWindow = window.open(winSource, "browseWindow", "width=400, height=200"); browseWindow.opener.document.getElementById("divDisplay").textContent = "Child Window Restored"; } } </script> </body> </html>
Output
Clicking ‘Go To’ button with unauthorized Full Name set −
Clicking ‘Go To’ button with authorized Full Name set −
- Related Articles
- HTML DOM addEventListener() Method
- HTML DOM normalize( ) Method
- HTML DOM writeln() Method
- HTML DOM insertAdjacentElement( ) Method
- HTML DOM insertAdjacentHTML( ) Method
- HTML DOM insertAdjacentText( ) Method
- HTML DOM insertBefore( ) Method
- HTML DOM isDefaultNamespace( ) Method
- HTML DOM isEqualNode( ) Method
- HTML DOM isSameNode( ) Method
- HTML DOM item( ) Method
- HTML DOM appendChild() Method
- HTML DOM blur() Method
- HTML DOM click() method
- HTML DOM cloneNode() method

Advertisements