- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM writeln() Method
The HTML DOM writeln() 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 appends arguments to a new line.
Syntax
Following is the syntax −
document.write(agruments)
Example
Let us see an example of HTML DOM document writeln() method −
<!DOCTYPE html> <html> <head> <title>HTML DOM writeln()</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-writeln( )</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.writeln("<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 −
Advertisements