JavaScript USES document.write to output content instances to the page

  • 2020-03-30 04:06:42
  • OfStack

The document.write command outputs text to the page

This example USES the document.write command of JavaScript to output the specified text to the page. The code is as follows:


<script type="text/javascript">
document.write(" I am the text output to the page! ");
</script>

Save the above part of the code as write.html (or write.htm) in a text editor. Double-click on the write.html to run it (actually using a browser like IE to open the file), and you'll see the following text:

 I am the text output to the page! 

prompt

If you use Internet Explorer, you are prompted: "in order to help protect security, Internet Explorer has restricted this page to run scripts or ActiveX Spaces that can access the computer." , then select "allow blocked content" to allow Internet explorer to run the JavaScript code above.

Document.write outputs text with HTML tags to the page

If the text output to the page is with HTML tags, just put the tags in the output text:


<script type="text/javascript">
document.write("<h1> I am the text output to the page! </h1>");
</script>

Example syntax interpretation

Similar to the previous (link: #), document.write is a standard JavaScript syntax command that outputs a specified string to a Web page. The character to be output is called "" or "and put into document.write().

The document.write command and the pop-up alert command used in this example will be frequently used in future JavaScript learning, please be sure to use it skillfully.


Related articles: