3 Replies - 1574 Views - Last Post: 30 August 2008 - 07:58 AM Rate Topic: -----

#1 megglz   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

slideshow works perfectly in firefox but generates error in IE

Post icon  Posted 30 August 2008 - 03:30 AM

My slideshow works perfectly in Firefox but I've noticed that when viewed in IE that my slideshow still works well but generates the following error

Error in IE6/7
Line: 1
Char: 1
Error: Object expected
Code: 0 



Here is my source code and the code of the following files that I use:

Source code of page:
<!DOCTYPE html
 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Home</title>
<link rel="stylesheet" type="text/css" media="screen,projection" href="css/style.css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" media="screen,projection" href="css/style-ie.css" />
<![endif]-->
<script language="Javascript" type="text/javascript" src="slideShow.php"></script>
<script type="text/javascript" src="class.photofader.js"></script>
<script language="Javascript"type="text/javascript">
var counter = 0;
var showImageFor = 2; //seconds

function runImages(){
  milliseconds = showImageFor * 1000;
  setInterval("showImage()", milliseconds);
}

</script>
</head>
<body onload="runImages()">
<div class="all">
	<div class="top">
		<div class="top-icons"><a href="index.html"><img src="images/icon_home.png" width="27" height="27" alt="Home" title="" /></a><a href="search.html"><img src="images/icon_search.png" width="11" height="11" alt="Search" title="" /></a><a href="contact.html"><img src="images/icon_mail.png" width="11" height="8" alt="Mail" title="" /></a></div>
	<a href="#" class="logo"><img src="images/logo.png" width="176" height="104" alt="" /></a>

<div class="photoholder2" id='photoholder'>
<script type="text/javascript">

function randOrd(){
	return (Math.round(Math.random())-0.5); }

images.sort( randOrd );

		var speed = 15; // Lower numbers yield a faster transition - must be 2 or higher
		var delay = 2; // Number of seconds between each slide transition
		var pf = new photofader("pf","photoholder",images);
	</script>

</div>
</body>



slideshow.php
<?
ob_start(); //Output buffering
//first we send the header to the browser to process the page
//as Javascript
header("content-type: application/x-javascript");
$imgDir = "images/"; // the directory the images reside in
$counter = 0; // our file counter;
$list = "";
//regex pattern to check file extensions. Name of files:
$pattern="(^image1)|(^image2) |(^image3)|(^image4)|(^image5)|(^image6)|(^image7)|(^image8)|(^image9)|(^image10)|(^image11) |(^image12)|(^image13)";

//read through the dir and create the img list
if($dir = opendir($imgDir)) {
 while(false !== ($file = readdir($dir))){
  if(eregi($pattern, $file)){
	$path  = $imgDir . $file;
	$list .= 'images['.$counter.']="'.$path .'";' .chr(13);
	$counter++;
   }
  }
  closedir($dir);
}
//echo the array declaration
echo "var images = new Array()" . chr(13);
echo $list;
ob_end_flush();
?>



class.photofader.js
function photofader(nm, mainDiv, imgArr){
	this.name		= nm;
	this.imgArr = imgArr;
	this.curImg = 0;
	this.curDiv = 1;
	
	var mainDv = document.getElementById(mainDiv);
	
	document.pfObj = this;
	
	document.write("<style type='text/css'>\n");
	document.write("#pf_photo1 img { visibility:hidden; }\n");
	document.write("#pf_photo1 { position:absolute; z-index: 1; }\n");
	document.write("#pf_photo2 { position:absolute; z-index: 0; }\n");
	document.write("</style>");
	
	this.initImages = function() {
		document.write("<scr");
		document.write("ipt type='text/javascript'>\n");
		for(var i=0; i<this.imgArr.length; i++){
			document.write("var img"+i+" = new Image();\n");
			document.write("img"+i+".src = '"+ this.imgArr[i] +"';\n");
		}
		document.write("document.pfObj.start();\n");
		document.write("</scr");
		document.write("ipt>\n");
		
	}
	
	this.start = function(){
		var hldr1 = "pf_photo1";
		var hldr2 = "pf_photo2";
		
		var dv1 = document.createElement("div");
				dv1.id = "pf_photo1";
				dv1.innerHTML = "<img src='"+ imgArr[0] +"' />";
		var dv2 = document.createElement("div");
				dv2.id = "pf_photo2";
		
		mainDv.appendChild(dv1);
		mainDv.appendChild(dv2);
		
	  image1 = document.getElementById(hldr1).childNodes[0];
		
	  setOpacity(image1, 0);
	  image1.style.visibility = 'visible';
	  fadeIn(hldr1,0);
	}
	
	this.initImages();
}
	
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
	obj = document.getElementById(objId).childNodes[0];
	if (opacity < 100) {
			speed = (speed < 2)?2:speed;
	  setOpacity(obj, opacity);
			opacityDif = Math.ceil((100-opacity)/speed);
			opacity += opacityDif;
	  //opacity += 2;
	  window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
	}
		else
			setTimeout("swapImages()",delay*1000);
  }
}

function swapImages(){
	// find out which 
	if(document.pfObj.curImg == document.pfObj.imgArr.length-1)
		document.pfObj.curImg = 0;
	else 
		++document.pfObj.curImg;

	// now get the div to hld the new image
	var dvName	= (document.pfObj.curDiv == 1)?"pf_photo2":"pf_photo1";
	var eDivName		= (document.pfObj.curDiv == 1)?"pf_photo1":"pf_photo2";
	document.pfObj.curDiv = (document.pfObj.curDiv == 1)?2:1;
	
	var tgtDiv = document.getElementById(dvName);
	var eDiv = document.getElementById(eDivName);
	
	// now fill the target div
	tgtDiv.innerHTML = "<img src='"+ document.pfObj.imgArr[document.pfObj.curImg] +"' style='visibility:hidden;' />";
	
	//move the divs around in z-index
	eDiv.style.zIndex = 0;
	tgtDiv.style.zIndex = 1;
	
	// And finally fade in the image
	
  var img = tgtDiv.childNodes[0];
	
  setOpacity(img, 0);
  img.style.visibility = 'visible';
  fadeIn(tgtDiv.id,0);
}



Anyone have any ideas how I could overcome this error in IE?

Is This A Good Question/Topic? 0
  • +

Replies To: slideshow works perfectly in firefox but generates error in IE

#2 JBrace1990   User is offline

  • D.I.C Addict
  • member icon

Reputation: 112
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: slideshow works perfectly in firefox but generates error in IE

Posted 30 August 2008 - 06:09 AM

IE Constantly has different ways of viewing the web. Quite frankly, i think you should just tell people viewing the site in IE to go get Firefox and save themselves a headache =P
Was This Post Helpful? 0
  • +
  • -

#3 dineeshd   User is offline

  • member icon

Reputation: 39
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: slideshow works perfectly in firefox but generates error in IE

Posted 30 August 2008 - 06:11 AM

Or you can recommend Opera.... :D
Was This Post Helpful? 0
  • +
  • -

#4 megglz   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

Re: slideshow works perfectly in firefox but generates error in IE

Posted 30 August 2008 - 07:58 AM

Hehe I wish :P

Think I found my problem

function showImage(){
  if(counter == images.length){
	counter = 0;
  }
  document.images[imageContainer.src] = images[counter];
  counter++;
}



If I remove
  document.images[imageContainer.src] = images[counter];



It still runs fine and no errors coming up in IE :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1