

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 open() Method
The DOM open() method set a node specified in its parameter to an attribute node using its name in an HTML document.
Syntax
Following is the syntax −
document.open(type,replace);
Here type represent type of document and replace represent whether the history entry for the new document inherits the history entry from the document which opened this document or not.
Example
Let us see an example of open() method −
<!DOCTYPE html> <html> <head> <style> body{ text-align:center; color:#fff; background: #ff7f5094; } .btn{ background:#0197F6; border:none; height:2rem; border-radius:2px; width:35%; margin:2rem auto; display:block; color:#fff; outline:none; cursor:pointer; } </style> </head> <body> <h1>DOM open() Method Demo</h1> <button onclick="openMethod()" class="btn">Click me to try Open() Mehtod</button> <script> function openMethod() { document.open(); document.write(` <style> body{ text-align:center; color:#fff; background: #ff7f5094; } </style> <h1>DOM open() Method Demo</h1> <p>New document</p> `); document.close(); } </script> </body> </html>
Output
This will produce the following output −
Click on the “blue” button to open a new output stream using open() method.
- Related Questions & Answers
- HTML DOM Details open property
- HTML DOM addEventListener() Method
- HTML DOM removeAttributeNode() Method
- HTML DOM setAttributeNode() Method
- HTML DOM setNamedItem() Method
- HTML DOM removeNamedItem() Method
- HTML DOM removeEventListener() Method
- HTML DOM replaceChild() Method
- HTML DOM querySelector() Method
- HTML DOM querySelectorAll() Method
- HTML DOM removeChild() Method
- HTML DOM removeAttribute() Method
- HTML DOM insertAdjacentElement( ) Method
- HTML DOM insertAdjacentHTML( ) Method
- HTML DOM insertAdjacentText( ) Method
Advertisements