Joachim: lokal funktioniert, online nicht

Beitrag lesen

Hi,

wie ich schon schrieb, lokal funktioniert das Script ohne Probleme. Der Bildpfad ist auch korrekt, das habe ich schon (mehrfach) überprüft.

Aber mein Test gibt mir (beschränkt auf 20) wie gewünscht das html aus:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>

<style type="text/css">
  a {border: 10px solid #000}
  img  {border: 10px solid green}
</style>
</head>
<body>
    <div>
        <script type="text/javascript">
            var currentBannerId = 0;
            var bannerArray     = new Array();
            var bannerClicked   = false;
            var cnt = 0; // TEST

addBannerToArray();
            currentBannerId = Math.floor( Math.random() * bannerArray.length );

// create new Banner
            function Banner(url, image, ziel) {
              this.url   = url;
              this.image = image;
              this.ziel = ziel;
            }
            // add the banner to the bannerArray
            function addBannerToArray() {
              bannerArray.push(new Banner("http://www.example.de", "mein_bild1.gif", "_blank"));
              bannerArray.push(new Banner("http://www.example.de", "mein_bild2.gif", ""));
              bannerArray.push(new Banner("http://www.example.de", "mein_bild3.gif", ""));
              bannerArray.push(new Banner("http://www.example.de", "mein_bild4.gif", "_blank"));
              bannerArray.push(new Banner("http://www.example.de", "mein_bild5.gif", ""));
            }

// display all banner from the bannerArray
            function displayBanner() {
              cnt ++;
              if (cnt > 20) return; //TEST
              currentBannerId = (currentBannerId == bannerArray.length-1) ? 0 : currentBannerId + 1;
              updateBanner();
              setTimeout('displayBanner()', 2000);
            };

// update the banner with the currentBannerId
            function updateBanner() {

var innerHTML = "<img border="0" src="bilder/" + bannerArray[currentBannerId].image + ""/>";
              if (!bannerClicked) {
                innerHTML = "<a style="cursor:pointer;" id="bannerLink" onclick="openLink(" + currentBannerId + ")">" + innerHTML + "</a>";
              }
              document.getElementById("bannerLayer").innerHTML = innerHTML;

body =  document.getElementsByTagName("body")[0];
              xxx =  innerHTML.replace("<","[");
              xxx =  xxx.replace(">","]");
              txt=  document.createTextNode(xxx);
              br =  document.createElement("br");

body.appendChild(txt);
              body.appendChild(br);

}

// open link behind the banner with the currentBannerId
            function openLink(id) {
              bannerClicked = true;
              document.getElementById("bannerLink").onclick = "";
              if (bannerArray[id].ziel == "_blank") {
                alert("blank: " + bannerArray[id].url);
                return;
                newAdWindow = window.open(bannerArray[id].url);
              newAdWindow.focus();
              }
              else {
                alert("self: " + bannerArray[id].url);
                return;
               window.location = bannerArray[id].url;
               }
            }
        </script>
    </div>
    <div id="bannerLayer" style="margin:0 0 20px 0">xxx</div>
    <script type="text/javascript">displayBanner();</script>
</body>
</html>

window.location = bannerArray[id].url;

Die Eigenschaft heisst übrigens: "href"

Gruesse, Joachim

--
Am Ende wird alles gut.