View Full Version : Help with using external script files

Jim Weinberg
04-01-2006, 01:42 PM
John has asked me to post this instead of contacting him directly, so here is my initial question and his response. I would appreciate it if someone could answer the question about imbedding the call within an "if" statement, though.

********************* Question *****************************
Hi John.

I've read your postings about using external script files and while I
believe that I have met all of the requirements you specified, I can't
get my external file to work. I would like to have this script included
in about half of my pages, which is why I want to use an external file.
I've attached it in case there's something unique about it. The call
line is:

<script src="ScrollArrows.js" type="text/javascript"></script>

and, yes, it's in the same folder as the pages that will call it.

Can you help?

Also, once it's working, can the call be put inside an "if" statement?
What I really want to do in only have the script execute if the viewer's
viewing area is less than a particular size.

********************* John's Response ***********************
you cannot have this:

<div id="staticbuttons2" style="position:absolute;">
<a href="javascript:" onmouseover="myspeed=thespeed" onmouseout="myspeed=0"><img
src="hold/arrows_dn.gif" border="0"></a></div>
<div id="staticbuttons" style="position:absolute;">
<a href="javascript:" onmouseover="myspeed=-thespeed" onmouseout="myspeed=0"><img
src="hold/arrows_up.gif" border="0"></a><br>


or this:


in an external script file. You can just get rid of the </script> and replace the top part (including the <script>) with:

document.write('<div id="staticbuttons2" style="position:absolute;">')
document.write('<a href="javascript:" onmouseover="myspeed=thespeed" onmouseout="myspeed=0">')
document.write('<img src="hold/arrows_dn.gif" border="0"></a></div>')
document.write('<div id="staticbuttons" style="position:absolute;">')
document.write('<a href="javascript:" onmouseover="myspeed=-thespeed" onmouseout="myspeed=0">')
document.write('<img src="hold/arrows_up.gif" border="0"></a><br></div>')

04-01-2006, 01:44 PM
There are ways of conditionally linking in a script, such as:

if(condition) document.write('<script type="text/javascript" src="test.js"><\/script>');However, to help other than that, I would have to see your page.