JavaScript is an interpreted language. That means: no compilation. You just write code and attach it to HTML.
<!DOCTYPE HTML>
<html>
<body>
<p>Header...</p>
<script>
alert('Hello, World!')
</script>
<p>...Footer</p>
</body>
</html>
The simplest way is to put JavaScript directives into
SCRIPT
tag somewhere inside the page.
Here is a
SCRIPT
tag containing single JavaScript statement. Please click the ‘Show’ button to see the example.
Note that contents of the
SCRIPT
block is not shown, instead, it is executed.
This example makes use of following elements:
<script> ... </script>
<script>
tag tells browser that there is executable content inside. In older HTML standard, namely HTML4, a special attributetype
was required. Although more up-to-date HTML5 makes it optional.
Browser:- Starts showing the page, shows
Header
- Switches to JavaScript mode inside this tag and executes the contents of
<script>
- Returns back to HTML-mode and continues with the page, outputs
Footer
.
- Starts showing the page, shows
alert(...)
- Outputs a message window on the screen and awaits until visitor presses OK
- Tag:
- java script
- hello world
0 comments:
Post a Comment