FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php / javascript script works in FireFox browser, but not IE





spider
Edit by wumingsden: next time you post pieces of code please place them in the "code" tags. If the code is long, like the stuff below, then please use www.pastebin.com (it is currently down which is why I haven't transferred it.

thank you.
wumingsden




ok,,, I found this banner script online someplace, and been trying to get it to work with my site... unfortunately when i used it the way it was,,, it would place the wrong banners in the wrong places,, messing up the site,,, below is the code after I somewhat repaired it didnt do much,,,...
I also think my todaysDate() could be done another way or better,, not sure yet,,, you can see what its doing at http://tusc-oh.com

Code:

<?PHP
// Functions:
include '../inc/config.php';
// Gives today's date with no time
function todaysDate()
{
   list($dd,$mm,$yyyy) = split("-",date("d-m-Y",time()));
   return makeDateValue($dd,$mm,$yyyy);
}

function makeDateValue($dd,$mm,$yyyy)
{
   return mktime(0, 0, 0, $mm, $dd, $yyyy);
}


?>
<SCRIPT LANGUAGE="JavaScript">
// Setup
var curAd;
var ads = new Array();
var delays = new Array();
var linx = new Array();
var external = new Array();
function displayAd()
{
   var adLink = document.getElementById("ADLINK");
   var ad = document.getElementById("AD");
   if (ads.length)
   {   
      ad.src = "<? echo $domain_ban; ?>/ads/"+ads[curAd];
      adLink.href=linx[curAd];
      if (external[curAd])
      {
         adLink.target="_blank";
      }
      else
      {
         // It's one of our own!
         adLink.target="_self";
      }
      if (ads.length > 1)
         // Skip refresh if we only have 1 ad!
         setTimeout("displayAd()",delays[curAd]*1000);
      // Move on
      curAd = (++curAd) % ads.length;
   }
}
</SCRIPT>

<DIV align=center>
<A id=ADLINK href="#">
<IMG id=AD border=0 src="#">
</A>

<SCRIPT LANGUAGE="JavaScript">
// Setup
var i = 0;

// PHP generated JavaScript array:
<?php
$fd = fopen ("".$domain_ban."ads/".$_REQUEST['size']."_ads.csv", "r");
//$fd = fopen ("./Ads/ads.csv", "r");
if ($fd)
{
   $adsUsed = 0;
   $today = todaysDate();
   $line = null;
   while (!feof ($fd))
   {
      if (!$line)
      {
         // Skip header
         $line = fgets($fd, 4096);
      }
      else
      {
         $line = fgets($fd, 4096);
         if (strlen($line) > 10)
         {
            list($startDate,$durationMonths,$adDurationSecs,$pipeSeparatedImages,$URL) = split (",", $line, 5);
            list($dd,$mm,$yyyy)= split ("\/", $startDate, 3);
            $startDateTime = mktime(0, 0, 0, $mm, $dd, $yyyy);
            $endDateTime = mktime(0, 0, 0, $mm + $durationMonths, $dd, $yyyy);
            if ($durationMonths < 0 || ($durationMonths > 0 && ($startDateTime <= $today ) && ($today <= $endDateTime)))
            {
               // We've got a contender
               ++$adsUsed;
               $image = split("\|",$pipeSeparatedImages);
               foreach($image as $anImage)
               {
                  if (strtolower(substr($pipeSeparatedImages,0,7))=="http://")
                  {
                     echo "external[i]=true;\n";
                  }
                  echo "ads[i] = \"$anImage\";\n";
                  echo "linx[i] = \"".rtrim($URL)."\";\n";
                  echo "delays[i++] = $adDurationSecs;\n";
               }
            }
         }
      }
   }
   fclose($fd);
}
?>
// Prevent same start ad being shown on every new page.. add random element
curAd = <?php echo rand(0,$adsUsed - 1); ?>;
displayAd();
</SCRIPT>
</DIV>


my problem now is when I use the script, the first banner will show,, but the rest will not....

this is what its suppose to look like in the html when it shows:

Notice: ads[i] has a gif image...

Code:

<SCRIPT LANGUAGE="JavaScript">
// Setup
var i = 0;

// PHP generated JavaScript array:
ads[i] = "120x90.gif";
linx[i] = "http://tusc-oh.com/b/index.php";
delays[i++] = 15;
// Prevent same start ad being shown on every new page.. add random element
curAd = 0;
displayAd();
</SCRIPT>
</DIV></td><td valign="top"><SCRIPT LANGUAGE="JavaScript">
// Setup
var curAd;
var ads = new Array();
var delays = new Array();
var linx = new Array();
var external = new Array();
function displayAd()
{
   var adLink = document.getElementById("ADLINK");
   var ad = document.getElementById("AD");
   if (ads.length)
   {   
      ad.src = "http://tusc-oh.com/b//ads/"+ads[curAd];
      adLink.href=linx[curAd];
      if (external[curAd])
      {
         adLink.target="_blank";
      }
      else
      {
         // It's one of our own!
         adLink.target="_self";
      }
      if (ads.length > 1)
         // Skip refresh if we only have 1 ad!
         setTimeout("displayAd()",delays[curAd]*1000);
      // Move on
      curAd = (++curAd) % ads.length;
   }
}
</SCRIPT>

<DIV align=center>
<A id=ADLINK href="#">
<IMG id=AD border=0 src="#">
</A>


Now, the next banner will show up the exact same way with an image, like below... (this is the same as the code from above, I just took out the main part I wanted to talk about...)
it has a different size image but doesnt show up in IE...

Code:

// PHP generated JavaScript array:
ads[i] = "728x90.gif";
linx[i] = "http://tusc-oh.com/b/index.php";
delays[i++] = 15;
// Prevent same start ad being shown on every new page.. add random element
curAd = 0;
displayAd();


Now,,, when I use Firefox web browser, It works fine...
any suggestions?

Sorry so large...
sonam
I don't know is it problem in JavaScript or PHP or both but when I open propertis for your images in Firefox I got for all:

http://tusc-oh.com/b//ads/120x90.gif

In IE only first have this http definiton others are:

http://tusc-oh.com/#


I think the path to banner is not corect.

Sonam
spider
no, it ok, its been fixed on the home server, but didnt matter on the path there for just //....
and the # is suppose to be there on the next one...


sorry wumingsden...

I emailed the original developer of this script,, Hoping he can help... might even give him the code afterwards as and outsiders update for people to try....
and if can get it to work,, want to put admin script on it,,,,
this is a banner script that posts banner ads and shuffles throught the banners by seconds and not refresh of pages... it also lets you specify a start date for a client, and so many months for the banner to be shown...
show not going by clicks, views or what not,, can just do monlthly banner advertising....

thanks anyhow,, Ill update this thread later when I know more..
spider
ok,,, this is what the creator told me.... I have alot more on my hands than I thought...

Creator:

I'm afraid it will take quite a bit of work to make it able to display more than one advert. It was only ever designed for one, so is pretty-much hard-coded that way.

As a hint: the problems are with the fact that we retrieve the DOM elements for the IMG and LINK by the fixed names "ADLINK" and "AD" - you'd need the ability to rename these - adding a number etc. Next problem will be setting the "timeout" so that they are updated according to the frequency. Last problem: you probably don't want the same ad displayed multiple times, so will need to cater for this.

Any Suggestions....lol?
looks like im going to start from scratch and learn some more javascript and / or ajax with php to code my own... educations never stops....
sonam
I thing that PHP is the best way for solved your problem but here is one more question, did you want to use same tamplate (ads on same place) for all pages or different.

Sonam
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.