Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External Javascript file with image addresses

Status
Not open for further replies.

jaslr

Programmer
Joined
Aug 16, 2001
Messages
67
Location
AU
Ok, I have my html page called test.htm, my external javascript file called images.js and one of my images called banner_02.gif. They are all in the same directory.

I am doing this so I only need to change the addresses of several images from one file that will then be used across several pages.

This is my html code (don't mind the rest, just my variable imSRC = banner:


<head>
</head>

<body>
<script language=&quot;JavaScript&quot; src=&quot;images.js&quot;>
function makeIm() {
NS4=(document.layers);
IE4=(document.all);
scaleWidth = true;
scaleHeight = true;
imSRC = banner;
if (NS4) {
origWidth = innerWidth;
origHeight = innerHeight;}
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();}
if (NS4) onresize = reDo;
if (IE4) onresize = reDoIE;
function reDoIE(){
imBG.width = document.body.clientWidth;
imBG.height = document.body.clientHeight;}
winWid = (NS4) ? innerWidth : document.body.clientWidth;
winHgt = (NS4) ? innerHeight : document.body.clientHeight;
imStr = &quot;
+ &quot; style='position:absolute;left:0;top:0;z-index:-1'>&quot;
+ &quot;<img name='imBG' border='0' src=&quot;+imSRC;
if (scaleWidth) imStr += &quot; width=&quot;+winWid;
if (scaleHeight) imStr += &quot; height=&quot;+winHgt;
imStr += &quot;>
&quot;;
document.write(imStr);}
makeIm();
</script>

</body>



------------------------

Now, I aren't sure how I should write images.js

This is all I have:

var banner = &quot;banner_02.gif&quot;;

--------------------------

I know that test.htm is reaching images.js, because when I remove script src=&quot;images.js&quot; I get an error with the variable banner.

How do I write the external javascript file?

Regards
JRoberts
 
may be i've missed something, but when you include externall script to your page, this script section have to be blank.. or else nothing of its content won't be interpretated (wrong word, i guess, but hope you got what i meant)

so, use:

<script language=&quot;JavaScript&quot; src=&quot;images.js&quot;>
</script>

<script>
//the rest of your code goes here
</script>

Victor
 
ok, i now understand that.
but how do i write the var banner=&quot;banner_02.gif&quot; bit?
 
hie

you have a typo:

...imStr = &quot; - unterminated string
+ &quot; style='position...
i guess there have to be ..=&quot;<div &quot;+..

the rest have to be working just like you wrote..

small question:
( may be not to jaslr but to anyone)
why did you included all of the functions in one? (in makeIm()) i've seen this somewhere before, but have never used this technique..

So, people, what would you say on this subject? (may be it is wrong, may be it is GOOD)
i guess it is some kind of classes's methods emulation.. Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top