Hallo,
Ich habe gerade erst mit Javascript angefangen und möchte nun ein Javascript-Code aus meiner HTML datei ausgliedern, damit ich nicht jedesmal den Code in jede Datei einfügen muss. Bisher hat es bei mir aber leider nicht funktioniert.
Wäre super nett wenn mir jemand eventuell ein Tipp oder die Lösung schicken könnte wie ich den Code mit den richtigen befehlen und so weiter auszugliedern hab.
Danke schonmal für die Hilfe
<html>
<head><
<title>Menue</title>
<link rel="stylesheet" title="Default" href="CSS/navigation.css" type="text/css" media="screen">
<link rel="stylesheet" title="Default" href="CSS/index.css" type="text/css" media="screen">
<script type="text/javascript">
theimage = new Array();
// The dimensions of ALL the images should be the same or some of them may look stretched or reduced in Netscape 4.
// Format: theimage[...]=[image URL, link URL, name/description]
theimage[0]=["images/banner/banner1.jpg", "http://www.google.de", "xx"];
theimage[1]=["images/banner/banner2.jpg", "http://www.google.de", "xx"];
theimage[2]=["images/banner/banner3.jpg", "http://www.google.de", "xx"];
theimage[3]=["images/banner/banner4.jpg", "http://www.google.de", "xx"];
theimage[4]=["images/banner/banner5.jpg", "http://www.google.de", "xx"];
///// Plugin variables
playspeed=5000;// The playspeed determines the delay for the "Play" button in ms
//#####
//key that holds where in the array currently are
i=0;
//###########################################
//if random
function SetRandom() {
tempimage = new Array();
for(p=0; p<theimage.length; p++){
for(p1=0; p1>-1; p1) {
tempNum = Math.floor(Math.random()*theimage.length)
if(!tempimage[tempNum]){
tempimage[tempNum]=theimage[p];
break;
}
}
}
for(p=0;p<theimage.length;p++)theimage[p]=tempimage[p];
}
//if random order
SetRandom()
//###########################################
window.onload=function(){
//preload images into browser
preloadSlide();
//set the first slide
SetSlide(0);
//autoplay
PlaySlide();
}
//###########################################
function SetSlide(num) {
//too big
i=num%theimage.length;
//too small
if(i<0)i=theimage.length-1;
//switch the image
document.images.imgslide.src=theimage[i][0];
//if they want name of current slide
document.getElementById('slidebox').innerHTML=theimage[i][2];
}
//###########################################
function PlaySlide() {
if (!window.playing) {
PlayingSlide(i+1);
if(document.slideshow.play){
document.slideshow.play.value=" Stop ";
}
}
else {
playing=clearTimeout(playing);
if(document.slideshow.play){
document.slideshow.play.value=" Play ";
}
}
// if you have to change the image for the "playing" slide
if(document.images.imgPlay){
setTimeout('document.images.imgPlay.src="'+imgStop+'"',1);
imgStop=document.images.imgPlay.src
}
}
//###########################################
function PlayingSlide(num) {
playing=setTimeout('PlayingSlide(i+1);SetSlide(i+1);', playspeed);
}
//###########################################
function preloadSlide() {
for(k=0;k<theimage.length;k++) {
theimage[k][0]=new Image().src=theimage[k][0];
}
}
</script>
</head>
<body>
<div id="head">
<form name="slideshow">
<table border="0" cellpadding="2" cellspacing="0" >
<tr>
<td width="20px"></td>
<td width="500px">
<a href="#" onmouseover="this.href=theimage[i][1];return false">
<script type="text/javascript">
document.write('<img name="imgslide" id="imgslide" src="'+theimage[0][0]+'" border="0">')
</script>
</a>
</td>
<td style="color:#FFFF00" width="20px"><div id="slidebox"></div></td>
</tr>
</table>
</form>
</div>
</body>
</html>