Skip to main content

JavaScript HOW To

The HTML <script> tag is used to insert a JavaScript into an HTML page.

Put a JavaScript into an HTML page
The example below shows how to use JavaScript to write text on a web page:

Example

<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
The example below shows how to add HTML tags to the JavaScript:

<html>
<body>
<script type="text/javascript">
document.write("<h1>Hello World!</h1>");
</script>
</body>
</html>





Example Explained

To insert a JavaScript into an HTML page, we use the <script> tag. Inside the <script> tag we use
the type attribute to define the scripting language.
So, the <script type="text/javascript"> and </script> tells where the JavaScript starts and ends:



<html>
<body>
<script type="text/javascript">
...
</script>
</body>
</html>
The document.write command is a standard JavaScript command for writing output to a page.
By entering the document.write command between the <script> and </script> tags, the browser
will recognize it as a JavaScript command and execute the code line. In this case the browser will
write Hello World! to the page:





<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>

Note: If we had not entered the <script> tag, the browser would have treated the document.write
("Hello World!") command as pure text, and just write the entire line on the page. Try it yourself
How to Handle Simple Browsers
Browsers that do not support JavaScript, will display JavaScript as page content.
To prevent them from doing this, and as a part of the JavaScript standard, the HTML comment tag
should be used to "hide" the JavaScript.
Just add an HTML comment tag <!-- before the first JavaScript statement, and a --> (end of
comment) after the last JavaScript statement, like this:

<html>
<body>
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
</body>
</html>

The two forward slashes at the end of comment line (//) is the JavaScript comment symbol. This
prevents JavaScript from executing the --> tag.





                  Prev                                                    Next














Comments

Popular posts from this blog

CSS Tutorial step by step

CSS   Introduction Cascading Style Sheets   (CSS) is a   style sheet language   used for describing the   look and formatting   of a document written in a markup language . While most often used to style   web pages   and user interfaces written in   HTML   and   XHTML . CSS is a cornerstone specification of   the web   and almost all web pages use CSS style sheets to describe their presentation. CSS is designed primarily to enable   the separation of document content from document presentation , including elements such as the   layout ,   colors , and   fonts .   This separation can improve content   accessibility , provide more flexibility and control in the specification of presentation characteristics, enable multiple pages to share formatting, and reduce complexity and repetition in the structural content (such as by allowing for   table less web design ). It   obvia...

TypingPad

TypingPad is a simple  text editor  for  Microsoft Windows  and a basic text-editing program which enables computer users to create documents. It was first released  in 2018, and has been included in  versions of  Microsoft Windows .  Features TypingPad  is a common text-only ( plain text ) editor. The resulting files—typically saved with the  .txt  extension—have no format tags or styles, making the program suitable for editing system files to use in a  DOS  environment and, occasionally, source code for later  compilation or  execution , usually through a  command prompt . It is also useful for its negligible use of system resources; making for quick load time and processing time, especially on under-powered hardware. TypingPad supports both left-to-right and right-to-left based languages. Historically,  TypinfPad offers only the most basic text manipulation functions, such as finding text. ...

WIFI Hack in two step by image

1. Open cmd   type netsh wlan show profiles and choose a connected network. 2.  Again type netsh wlan show profiles Discovery key=clear.