Publishing Books Using XML Technologies
Dr. Herong Yang, Version 4.01

How JavaScript Is Used in hyPub?

This section describes how JavaScript is used in hyPub.

In hyPub, I am suggesting that:

1. You should code common HTML contents that are shared by most of your Book Web pages, like banners, site navigation menu, and promotional items, as JavaScript functions. For example:

function writeMenu(subject) {
   document.write('[ <a href="/index.html">Home</a> | ');
   document.write('<a href="/news.html">News</a> | ');
   document.write('<a href="/search.html">Search</a> ]');
}

2. You can store those JavaScript functions in a JavaScript file called _hypub.js.

3. Link _hyPub.js to all Web pages in the "head" element as shown below:

<html>
<head>
...
<script type="text/javascript" src="_hypub.js"></script>
</head>
<body>
...
</body>
</html>

4. In the "body" of any Web page, wherever you want to insert a special common HTML contents, you just need to call the corresponding JavaScript function as shown here:

<body>
...
<script type="text/javascript">writeMenu("Top");</script>
...
</body>

5. If there is any need to change the common HTML contents in the future, for example, adding a new entry in the menu, all you need to do is to change the code in _hyPub.js. This is the biggest advantage of putting those common HTML contents into a single JavaScript file.

Sections in This Chapter

What Is JavaScript?

How JavaScript Is Used in hyPub?

Dr. Herong Yang, updated in 2007
How JavaScript Is Used in hyPub?