w3schools
  
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About

Document open() Method


Document Object Reference Document Object

Definition and Usage

The open() method opens an output stream to collect the output from any document.write() or document.writeln() methods.

Once all the writes are performed, the document.close() method causes any output written to the output stream to be displayed.

Note: If a document already exists in the target, it will be cleared. If this method has no arguments, a new window (about:blank) is displayed.

Syntax

document.open(MIMEtype,replace)

Parameter Description
MIMEtype Optional. The type of document you are writing to. Default value is "text/html"
replace Optional. If set, the history entry for the new document inherits the history entry from the document which opened this document


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The open() method is supported in all major browsers.


Example

Example

Open an output stream, add some text, then close the output stream:

<html>
<head>
<script type="text/javascript">
function createDoc()
  {
  var doc=document.open("text/html","replace");
  var txt="<html><body>Learning about the HTML DOM is fun!</body></html>";
  doc.write(txt);
  doc.close();
  }
</script>
</head>

<body>
<input type="button" value="New document" onclick="createDoc()" />
</body>
</html>

Try it yourself »

Example 2

Open an output stream (in a new window; about:blank), add some text, then close the output stream:

<html>
<body>

<script type="text/javascript">
w=window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();
</script>

</body>
</html>

Try it yourself »


Document Object Reference Document Object

Free Online Website Builder - No Downloading Needed

Create a free Flash website with our simple, online web design editing platform. Stunning templates and user-friendly tools make website building easy and fun.

Start Creating your free website now!


Altova® MapForce®
Graphical XML Mapping Tool from the Developers of XMLSpy®

Altova MapForce

Need an easy way to get data into XML, or transform XML to another format? MapForce lets you map XML data to/from any combination of XML, database, flat file, Excel 2007, XBRL, or Web services data. Then it transforms data instantly or auto-generates royalty-free code for recurrent conversions. New features in Version 2010!

  • Easy-to-use, graphical data mapping interface
  • Instant data transformation
  • XSLT 1.0/2.0 and XQuery code generation
  • Java, C#, and C++ code generation
  • Advanced data processing functions
  • Support for all major relational databases including SQL Server, IBM DB2, Oracle, and more
  • Visual Studio & Eclipse integration
  • Available in 32-bit and 64-bit versions

Download a fully-functional trial today!

  Altova MapForce

WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting
Top Web Hosting
Cheap UK Web Hosting
WEB BUILDING
XML Editor – Free Trial!
FREE Flash Website
FREE Web Templates
SEO Company
EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification
STATISTICS
Browser Statistics
Browser OS
Browser Display
FLIGHT TICKETS
Find the cheapest flight
to any destination now!
SHARE THIS PAGE