Simple Program: Displaying a Line of Text in a Web Page
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<!-- Fig. 6.2: welcome.html -->
<!-- Displaying a line of text. -->
<html xmlns = "http://www.w3.org/1999/xhtml">
Fig. 6.2 | Displaying a line of text.
Line 11 contains the XHTML opening comment tag <!--. Some older web browsers do not support scripting. In such browsers, the actual text of a script often will display in the web page. To prevent this from happening, many script programmers enclose the script code in an XHTML comment, so that browsers that do not support scripts will simply ignore the script. The syntax used is as follows:
script code here
// --> </script>
Lines 12–13 use the browser’s document object, which represents the XHTML doc-ument the browser is currently displaying. The document object allows you to specify text to display in the XHTML document. The browser contains a complete set of objects that allow script programmers to access and manipulate every element of an XHTML docu-ment. In the next several chapters, we overview some of these objects as we discuss the Document Object Model (DOM).
The </head> tag in line 16 indicates the end of the <head> section. Also in line 16, the tags <body> and </body> specify that this XHTML document has an empty body. Line 17 indicates the end of this XHTML document.
We are now ready to view our XHTML document in a web browser—open it in Internet Explorer or Firefox. If the script contains no syntax errors, it should produce the output shown in Fig. 6.2.
Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.