280 Part IV: Advanced CSS Techniques
Here’s an example of scripting, using JavaScript:
<html>
<head>
<script type=”text/javascript” language=”JavaScript”>
<!——
function foryou( ) {
alert(“A message for you!”);
}
//——>
</script>
Writing for users who disable scripts
Script languages were originally designed to be
harmless to a computer (dangerous commands
like disk formatting have been stripped from
script languages). Nonetheless, virus writers,
Trojan horse authors, and other social misfits
have found ways to use script to spy on people’s
data, damage files, and so on. However, you’ve
written the script examples in this chapter, so
you can trust them and test the examples.
But what about using scripts on the Internet? So
far, most people using IE seem to be permitting
scripts, so you might be safe inserting them into
your Web pages. If, however, a browser or user
refuses to permit scripts, you should offer an
alternative to scripting. You can, if necessary,
insert a <noscript>element in your code that
is executed if your script can’t execute because
of the user’s security settings. Inside this
<noscript>element, you can include CSS
styles, text explaining what the script did, or an
<a>link they can click for additional informa-
tion: whatever you think makes your page
acceptable comprehensible and aesthetically
pleasing if your script fails to run. Here’s an
example:
<noscript>
<p>Sorry, you have configured
your browser to prohibit
scripting. If you want to
allow scripting in Internet
Explorer, adjust the set-
tings in the Tools➪Internet
Options dialog box. Click
the Security tab, and then
click the Custom Level
button and set the permis-
sions.
</noscript>
Sometimes using the <noscript>element
isn’t necessary because the script is merely
doing something visually attractive (like fading
a graphic image into the page for decoration).
You don’t need to provide an alternative for that
because presumably now that you’ve read this
book, your CSS-designed page is already gor-
geous without the added attractions offered by
animated scripted design elements. But if the
script does something essential, such as
making tiny text larger so it can be read or sim-
ulating opening a menu, you may want to
ensure that those who can’t execute scripts can
still get this important benefit via a hyperlink that
loads another page, or in some other fashion.