HTML DOM open() Method Last Updated : 09 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The DOM Open() method in HTML is the combination of the following three steps: Opens an output stream to collect the output.Collects output from the document.write() or document.writeln() methods.Runs the document.close to display the output written to the output stream. Syntax: document.open( MIMEtype, replace ) Parameter Values: This method accepts two parameters which are listed below: MIMEtype: It is the type of document, and it is an optional parameter. The default value of this parameter is "text/html".replace: It is an optional parameter. If this value is set then the history entry for the new document is inherit the history entry from the document. Example 1: In this example, we will use DOM Open() method HTML <!DOCTYPE html> <html> <head> <title>DOM open() Method</title> </head> <body> <p>GeeksforGeeks</p> <button onclick="Geeks()"> Click Here! </button> <script> function Geeks() { /* DOM open() method used here */ document.open("text/html", "replace"); document.write("Welcome to GeeksforGeeks"); document.close(); } </script> </body> </html> Output: Example 2: This example displays the output in a new window. HTML <!DOCTYPE html> <html> <head> <title>DOM open() Method</title> </head> <body> <p>GeeksforGeeks</p> <button onclick="Geeks()"> Click Here! </button> <script> function Geeks() { let x = window.open(); /* DOM open() method used here */ x.document.open("text/html", "replace"); x.document.write("Welcome to GeeksforGeeks"); x.document.close(); } </script> </body> </html> Output: Supported Browsers: The browser supported by the DOM open() method is listed below: Google Chrome 64Edge 12Internet Explorer 4Firefox 1Opera 51Safari 11 Comment More infoAdvertise with us K KV30 Follow Improve Article Tags : Web Technologies HTML Web technologies HTML-DOM Similar Reads HTML DOM getElementsByName() Method The getElementsByName() method returns collection of all elements of particular document by name. This collection is called node list and each element of the node list can be visited with the help of the index. Syntax: document.getElementsByName(name) Parameter:This function accepts name of document 2 min read HTML DOM getElementById() Method The getElementById() method returns the elements that have given an ID which is passed to the function. This function is a widely used HTML DOM method in web designing to change the value of any particular element or get a particular element. If the passed ID to the function does not exist then it r 3 min read HTML DOM getElementsByClassName() Method The getElementsByClassName() method in Javascript returns an object containing all the elements with the specified class names in the document as objects. Each element in the returned object can be accessed by its index. The index value will start with 0. This method can be called upon by any indivi 3 min read HTML DOM defaultView Property The DOM defaultView property in HTML is used to return the document Window Object. The window object is the open windows in the browser. Syntax:document.defaultView Return Value: It is used to return the current Window Object. Example 1: In this example use the defaultView property to get the window 2 min read HTML DOM forms Collection The DOM forms collection is used to return the collection of all <form> elements in a HTML document. The form elements are sorted as they appear in the source code. Syntax: document.forms Properties: It returns the number of form in the collection of elements. Methods: The DOM forms collection 4 min read HTML DOM referrer Property The DOM referrer property in HTML is used to return the URI of the page that linked to the current page. If the user navigates to the page directly or through a bookmark, then this value is an empty string. Syntax:document.referrer The below program illustrates the referrer property in HTML: Example 3 min read HTML DOM getNamedItem() Method The DOM getNamedItem() method in HTML is used to return the attribute node from the NamedNodeMap object.Syntax: namednodemap.getNamedItem( nodename )Parameter's Value: This method contains a single parameter nodename which is mandatory. The nodename is returned from the NamedNodeMap object. Return V 2 min read HTML DOM createEvent() Event Method The createEvent() method in HTML creates an event object of the specified type. The created event must be initialized before use. Syntax:document.createEvent(event_type)event_type: It is the required parameter and is used to specify the type of event. There are many types of events which are listed 2 min read HTML DOM getElementsByTagName() Method The getElementsByTagName() method in the HTML DOM allows the selection of elements by their tag name. It returns a collection of elements with the specified tag name within the specified document or element. To extract any info just iterate through all the elements using the length property. Syntax: 3 min read HTML DOM length Property The DOM length property in HTML is used to get the number of items in a NodeList object. A NodeList is a collection of child Nodes. For example, the NodeList of the body will contain all the child nodes in the body i.e. paragraphs, comments, headings, script, etc.Syntax: nodelist.lengthReturn Value: 2 min read Like