writeln method (document)
Writes a string followed by a new line character into the document stream.
The open method opens the output stream for writing.
When the document stream is opened, the write and writeln methods can be used to write some content into the document.
If the document is opened by the open method, the close method must be used to close the output stream.
Note: while the document is loading, the document stream is opened for writing.
In that case, there is no need to open and close the output stream.
After the document has been loaded, the open method (if at most two parameters are specified) clears the current document.
Note: the new line character does not cause line breaking in the rendered text, only means line breaking in the source code.
See the examples for details.After the document has been loaded, the open method (if at most two parameters are specified) clears the current document.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the data to display. The format of the text is specified by the second parameter of the open method. |
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the open, writeln and close methods to replace the contents of the document:
|
||||
<head> <script type="text/javascript"> function ReplaceContent () { document.open ("text/html"); document.writeln ("First line."); document.writeln ("Second line."); document.close (); } </script> </head> <body> <button onclick="ReplaceContent ();">Replace the contents of the document</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example is similar to the previous one, but the rendered text contains line breaking:
|
||||
<head> <script type="text/javascript"> function ReplaceContent () { document.open ("text/html"); document.write ("First line.<br />"); document.write ("Second line."); document.close (); } </script> </head> <body> <button onclick="ReplaceContent ();">Replace the contents of the document</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments