HTML and CSS Reference
In-Depth Information
h e more you use HTML5, the more you need a script to get the most out of your Web pages.
h e most common scripting language used with HTML5 is JavaScript. Your browser has an
interpreter for JavaScript just as it does for HTML5. Fortunately, JavaScript is easy to learn
and can work in small snippets — even non-developers can do it.
To include JavaScript, all you need to do is to add a little script to the head of your page. Here's
the tag format:
< script type = ”text/javascript” >
h e JavaScript program goes into the remainder of the <script> container. h e following
HTML5 code ( ScriptTag.html in this chapter's folder at
smashinghtml5 ) shows how easy JavaScript is to learn.
< html >
< head >
< script type = ”text/javascript” >
alert ( “I can do JavaScript!” );
< meta http - equiv = ”Content-Type” content = ”text/html; charset=UTF-8” >
< title > A Taste of JavaScript </ title >
</ head >
< body >
A regular Web page ....
</ body >
</ html >
When you test that little program, you'll see an alert box pop up (shown in Figure 5-2).
Figure 5-2: A JavaScript alert window.
As a side note, you'll see that the JavaScript alert window is loaded before your Web page
loads. h at's because everything in the head container loads i rst. If you have a more elaborate
JavaScript program that will be used in your HTML5 page, you'll want to test it on dif erent
browsers and also put it in an external JavaScript i le. Figure 5-3 shows the same alert window
in Safari on an iPhone; you can clearly see that the Web page associated with the HTML5
code has not loaded.
Search WWH ::

Custom Search