Calling external js file

R

Rob

Hi everyone.

I have some main pages with an included header.htm page. The header has a
javascript image rotator. I have put the javascript in an external file in
my web called rotator.js - do I need to remove the first line,

<script LANGUAGE="JavaScript">?

I want to call the script from the body onload part in the main pages.
Please help with this statement. I can't get it right.

Also, what goes in the head of the main pages by way of script src= ?

I hope this make sense.

To summarise, I need..........

<body onload=*************> for main pages.
Any script reference in the head of the main pages (=src)
Whether to remove anything from the script itself.

Script below

<script LANGUAGE="JavaScript">
<!-- Begin
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3000;
// Duration of crossfade (seconds)
var crossFadeDuration = 5;
// Specify the image files
var Pic = new Array();
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'images/BG.jpg'
Pic[1] = 'images/fire_parts.gif'
Pic[2] = 'images/fa_p3.gif'
Pic[3] = 'images/extings_water.gif'
Pic[4] = 'images/exting_blankets.JPG'
Pic[5] = 'images/signs_stacked.jpg'
Pic[6] = 'images/nc_ic600.JPG'
Pic[7] = 'images/nc_ic400.jpg'
Pic[8] = 'images/nc.gif'

// do not edit anything below this line
var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad = new Image();
preLoad.src = Pic;
}
function runSlideShow() {
if (document.all) {
document.images.SlideShow.style.filter="blendTrans(duration=2)";
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
document.images.SlideShow.filters.blendTrans.Apply();
}
document.images.SlideShow.src = preLoad[j].src;
if (document.all) {
document.images.SlideShow.filters.blendTrans.Play();
}
j = j + 1;
if (j > (p - 1)) j = 0;
t = setTimeout('runSlideShow()', slideShowSpeed);
}
// End -->
</script>

Very many thanks

Rob
 
S

Stefan B Rusynko

Copy your script (see note) to notepad and save it as a .js file (say myscript.js)
Then in all page using it link it using <script LANGUAGE="JavaScript" src="myscript.js"></script>
Call the function(s) in the script using
<body onload="runSlideShow();" >

Note:
the .js file should not include the <script> and html comment (<!-- -->) tags



| Hi everyone.
|
| I have some main pages with an included header.htm page. The header has a
| javascript image rotator. I have put the javascript in an external file in
| my web called rotator.js - do I need to remove the first line,
|
| <script LANGUAGE="JavaScript">?
|
| I want to call the script from the body onload part in the main pages.
| Please help with this statement. I can't get it right.
|
| Also, what goes in the head of the main pages by way of script src= ?
|
| I hope this make sense.
|
| To summarise, I need..........
|
| <body onload=*************> for main pages.
| Any script reference in the head of the main pages (=src)
| Whether to remove anything from the script itself.
|
| Script below
|
| <script LANGUAGE="JavaScript">
| <!-- Begin
| // Set slideShowSpeed (milliseconds)
| var slideShowSpeed = 3000;
| // Duration of crossfade (seconds)
| var crossFadeDuration = 5;
| // Specify the image files
| var Pic = new Array();
| // to add more images, just continue
| // the pattern, adding to the array below
|
| Pic[0] = 'images/BG.jpg'
| Pic[1] = 'images/fire_parts.gif'
| Pic[2] = 'images/fa_p3.gif'
| Pic[3] = 'images/extings_water.gif'
| Pic[4] = 'images/exting_blankets.JPG'
| Pic[5] = 'images/signs_stacked.jpg'
| Pic[6] = 'images/nc_ic600.JPG'
| Pic[7] = 'images/nc_ic400.jpg'
| Pic[8] = 'images/nc.gif'
|
| // do not edit anything below this line
| var t;
| var j = 0;
| var p = Pic.length;
| var preLoad = new Array();
| for (i = 0; i < p; i++) {
| preLoad = new Image();
| preLoad.src = Pic;
| }
| function runSlideShow() {
| if (document.all) {
| document.images.SlideShow.style.filter="blendTrans(duration=2)";
| document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
| document.images.SlideShow.filters.blendTrans.Apply();
| }
| document.images.SlideShow.src = preLoad[j].src;
| if (document.all) {
| document.images.SlideShow.filters.blendTrans.Play();
| }
| j = j + 1;
| if (j > (p - 1)) j = 0;
| t = setTimeout('runSlideShow()', slideShowSpeed);
| }
| // End -->
| </script>
|
| Very many thanks
|
| Rob
|
|
 
M

Murray

Actually, the proper syntax for HTML 4 is this -

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

Make sure that your js file contains NO HTML, like comments. It should
contain ONLY javascript functions and variables definitions.

--
Murray

Stefan B Rusynko said:
Copy your script (see note) to notepad and save it as a .js file (say
myscript.js)
Then in all page using it link it using <script LANGUAGE="JavaScript"
src="myscript.js"></script>
Call the function(s) in the script using
<body onload="runSlideShow();" >

Note:
the .js file should not include the <script> and html comment (<!-- -->)
tags



| Hi everyone.
|
| I have some main pages with an included header.htm page. The header has
a
| javascript image rotator. I have put the javascript in an external file
in
| my web called rotator.js - do I need to remove the first line,
|
| <script LANGUAGE="JavaScript">?
|
| I want to call the script from the body onload part in the main pages.
| Please help with this statement. I can't get it right.
|
| Also, what goes in the head of the main pages by way of script src= ?
|
| I hope this make sense.
|
| To summarise, I need..........
|
| <body onload=*************> for main pages.
| Any script reference in the head of the main pages (=src)
| Whether to remove anything from the script itself.
|
| Script below
|
| <script LANGUAGE="JavaScript">
| <!-- Begin
| // Set slideShowSpeed (milliseconds)
| var slideShowSpeed = 3000;
| // Duration of crossfade (seconds)
| var crossFadeDuration = 5;
| // Specify the image files
| var Pic = new Array();
| // to add more images, just continue
| // the pattern, adding to the array below
|
| Pic[0] = 'images/BG.jpg'
| Pic[1] = 'images/fire_parts.gif'
| Pic[2] = 'images/fa_p3.gif'
| Pic[3] = 'images/extings_water.gif'
| Pic[4] = 'images/exting_blankets.JPG'
| Pic[5] = 'images/signs_stacked.jpg'
| Pic[6] = 'images/nc_ic600.JPG'
| Pic[7] = 'images/nc_ic400.jpg'
| Pic[8] = 'images/nc.gif'
|
| // do not edit anything below this line
| var t;
| var j = 0;
| var p = Pic.length;
| var preLoad = new Array();
| for (i = 0; i < p; i++) {
| preLoad = new Image();
| preLoad.src = Pic;
| }
| function runSlideShow() {
| if (document.all) {
| document.images.SlideShow.style.filter="blendTrans(duration=2)";
|
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
| document.images.SlideShow.filters.blendTrans.Apply();
| }
| document.images.SlideShow.src = preLoad[j].src;
| if (document.all) {
| document.images.SlideShow.filters.blendTrans.Play();
| }
| j = j + 1;
| if (j > (p - 1)) j = 0;
| t = setTimeout('runSlideShow()', slideShowSpeed);
| }
| // End -->
| </script>
|
| Very many thanks
|
| Rob
|
|
 
R

Rob

Thanks Stefan and Murray. I am sorted!

Much appreciated.

Rob

Murray said:
Actually, the proper syntax for HTML 4 is this -

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

Make sure that your js file contains NO HTML, like comments. It should
contain ONLY javascript functions and variables definitions.

--
Murray

Stefan B Rusynko said:
Copy your script (see note) to notepad and save it as a .js file (say
myscript.js)
Then in all page using it link it using <script LANGUAGE="JavaScript"
src="myscript.js"></script>
Call the function(s) in the script using
<body onload="runSlideShow();" >

Note:
the .js file should not include the <script> and html comment (<!-- -->)
tags



| Hi everyone.
|
| I have some main pages with an included header.htm page. The header has
a
| javascript image rotator. I have put the javascript in an external file
in
| my web called rotator.js - do I need to remove the first line,
|
| <script LANGUAGE="JavaScript">?
|
| I want to call the script from the body onload part in the main pages.
| Please help with this statement. I can't get it right.
|
| Also, what goes in the head of the main pages by way of script src= ?
|
| I hope this make sense.
|
| To summarise, I need..........
|
| <body onload=*************> for main pages.
| Any script reference in the head of the main pages (=src)
| Whether to remove anything from the script itself.
|
| Script below
|
| <script LANGUAGE="JavaScript">
| <!-- Begin
| // Set slideShowSpeed (milliseconds)
| var slideShowSpeed = 3000;
| // Duration of crossfade (seconds)
| var crossFadeDuration = 5;
| // Specify the image files
| var Pic = new Array();
| // to add more images, just continue
| // the pattern, adding to the array below
|
| Pic[0] = 'images/BG.jpg'
| Pic[1] = 'images/fire_parts.gif'
| Pic[2] = 'images/fa_p3.gif'
| Pic[3] = 'images/extings_water.gif'
| Pic[4] = 'images/exting_blankets.JPG'
| Pic[5] = 'images/signs_stacked.jpg'
| Pic[6] = 'images/nc_ic600.JPG'
| Pic[7] = 'images/nc_ic400.jpg'
| Pic[8] = 'images/nc.gif'
|
| // do not edit anything below this line
| var t;
| var j = 0;
| var p = Pic.length;
| var preLoad = new Array();
| for (i = 0; i < p; i++) {
| preLoad = new Image();
| preLoad.src = Pic;
| }
| function runSlideShow() {
| if (document.all) {
| document.images.SlideShow.style.filter="blendTrans(duration=2)";
|
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
| document.images.SlideShow.filters.blendTrans.Apply();
| }
| document.images.SlideShow.src = preLoad[j].src;
| if (document.all) {
| document.images.SlideShow.filters.blendTrans.Play();
| }
| j = j + 1;
| if (j > (p - 1)) j = 0;
| t = setTimeout('runSlideShow()', slideShowSpeed);
| }
| // End -->
| </script>
|
| Very many thanks
|
| Rob
|
|

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top