Calling an External Automatic Script


If you use a script in several different Web pages, you'll save time and avoid typos by creating an external script (in text-only format) and then calling the script from each page where it is used.

To call an external automatic script:

1.

Type <script.

2.

Type type="text/language-name", where language-name identifies the scripting language you're using: javascript, vbscript, etc.

3.

Type language="script", where script is the name of the scripting language you'll be using: JavaScript, VBScript, etc.

4.

Type src="/books/2/62/1/html/2/script.url", where script.url is the location on the server of the external script.

5.

If desired, type charset="code", where code is the official name for the set of characters used in the external script.

6.

Type >.

7.

Type </script>.

Figure 19.3. Here I've created an independent text file with the same script as in Figure 19.1. I can reference this external script from inside any (X)HTML file.


Figure 19.4. The src attribute not only references the script, it also automatically hides it from browsers that don't recognize the script tag.


Figure 19.5. The effect in the browser is the same as if it had been an internal script.


Tips

  • Using external scripts is a great way to keep older browsers from displaying your scripts as text. Since they don't understand the script tag, they ignore it (and the src attribute) completely. Use noscript to give those visitors using the older browsers an idea of what they're missing (see page 317).

  • The language attribute is deprecated. Nevertheless it is often used to maintain compatibility with older browsers.





HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net