[thelist] Validating JavaScript

Aylard JA (James) jaylard at equilon.com
Mon Mar 12 17:17:12 CST 2001


Kathy wrote:

> javascript (which I'm sure you've already figured out). It may help if you

> put all of your javascript functions and array declarations in an external

> file and include that external file in the page like this:
> 
> <script src="scriptname.js">

	Although there are a number of benefits to external script files,
one potential pitfall is that first-generation javascript-enabled browsers
(e.g., Netscape 2, IE 3) do not support them and will cough up errors when
the page attempts to call a function or reference a variable that is located
there. One simple way around at least certain aspects of this is to place
down-level content between the opening and closing <script> tags for the
first-generation browsers, e.g.:

<head>
<script type="text/javascript" src="scriptname.js">
  <!--
    function fnMouseOver() {}
    function fnMouseOut() {}
    function fnMouseClick() {}
  // -->
</script>
</head>
<body>
  <a href="foo.html" 
    onmouseover="fnMouseOver();"
    onmouseout="fnMouseOut();"
    onclick="fnMouseClick();"><img src="image.jpg" alt=""></a>
</body>

	Any browser that has second-generation javascript support or later
should ignore the content between the <script> tags and abide by the content
in the external file, while first-generation browsers will remain blissful
in their ignorance.

James Aylard

P.S. - Although this is a workaround that I "discovered" for myself, I think
that jeff may have suggested it in days long past. If so, jeff, feel free to
correct or improve upon anything I've written.




More information about the thelist mailing list