PDA

View Full Version : works in IE5 but not in IE6?


Mr J
12-10-2002, 09:55 PM
I have been told that the following script produces the error

"divA is undefined" in IE6

The script works ok in IE5.5

Could someone with IE6 knowledge check it out.




<HTML>
<HEAD>
<TITLE>Document Title</TITLE>

<SCRIPT language="javascript">
<!--
contents=new Array()
contents[contents.length]=new Array("pic1.jpg")
contents[contents.length]=new Array("pic2.jpg")
contents[contents.length]=new Array("pic3.jpg")
contents[contents.length]=new Array("pic4.jpg")
contents[contents.length]=new Array("pic5.jpg")
contents[contents.length]=new Array("pic6.jpg")
contents[contents.length]=new Array("pic7.jpg")

var preloadpics=new Array() // preloads images
for (i=0;i<=contents.length-1;i++) {
preloadpics[i]=new Image()
preloadpics[i].src=contents[i][0]
}

newTrans=new Array()
newTrans[newTrans.length] = "progid:DXImageTransform.Microsoft.Slide(bands = 1, slideStyle = 'push')";

var tranSpeed = 1.0; // how long transition takes in seconds
var pause = 2000 // in milliseconds
var advance = (tranSpeed*1000)+pause //
var i=0
var picnum=1
var loc=picnum-1

function RunMe(){
divA.style.filter = newTrans[i];
divA.filters[0].apply();
divA.innerHTML = "<img src='"+contents[picnum][0]+"'width='"+document.all.divA.style.width+"'height='"+document.all.divA.style.height+"'>"
divA.filters[0].play(tranSpeed);

loc=picnum
timer=setTimeout("RunMe()",advance)
if(i==newTrans.length-1){
i=-1}

if(picnum==contents.length-1){
picnum=-1
clearTimeout(timer)
}

i++
picnum++

}
setTimeout("RunMe()",(tranSpeed*1000)+pause)
// -->
</SCRIPT>
</HEAD>
<BODY>
<DIV id=divA style="position:absolute; left:200; top:100; width:100; height:100; font-size:35; text-align:center; filter(); border:5 inset blue;cursor:hand"><img src="pic1.jpg" width=100 height=100></DIV>

</BODY>
</HTML>

chrismiceli
12-10-2002, 10:25 PM
it is correct html syntax to put values in qutoes, try it here
<div id="divA"...

Leithakor
12-10-2002, 10:28 PM
Technically that's because DivA ISN'T defined. The code runs in the head, which means it is parsed before anything else (this includes the creation of the div element). You need to encase your code in a function (perhaps) and call it onload. That should fix your problem. I wouldn't use a setTimeout to compensate for possible system boot time. I'd just use the window.onload (or just onload) and run it from there. So instead of this line:

setTimeout("RunMe()",(tranSpeed*1000)+pause)

I'd replace it with this line

onload= runMe; (or is it runMe())?

Or if you NEED the delay
onload = setTimeout("RunMe()",(tranSpeed*1000)+pause)


Hope that helps.

Mr J
12-11-2002, 07:45 PM
Thanks guys but the person I did the script for used frontpage express to insert my script into his page and as usual frontpage messed it up

Leithakor
12-11-2002, 08:01 PM
Lol, why "doesn't" that surprise me? Well glad you got it working. Take care


James

cg9com
12-11-2002, 08:21 PM
Originally posted by Mr J
as usual frontpage messed it up
manual coding forever ;)

Leithakor
12-12-2002, 04:06 PM
Something I just noticed (this may also be where FP screwed it up) in runMe() you have these lines:


function RunMe(){
divA.style.filter = newTrans[i];
divA.filters[0].apply();
divA.innerHTML = "<img src='"+contents[picnum][0]+"'width='"+document.all.divA.style.width+"'height='"+document.all.divA.style.height+"'>"
divA.filters[0].play(tranSpeed);


divA.style can't be defined because divA as a variable hasn't been defined.

You'd need to make it look like this to define it ( in-red is what I added )


function RunMe(){
var divA = (document.getElementById) ? document.getElementById("divA") : (document.all) ? document.all["divA"] : (document.layers) ? document.layers["divA"] : null;
divA.style.filter = newTrans[i];
divA.filters[0].apply();
divA.innerHTML = "<img src='"+contents[picnum][0]+"'width='"+document.all.divA.style.width+"'height='"+document.all.divA.style.height+"'>"
divA.filters[0].play(tranSpeed);


I added all three type checks (all/layers/getElementById) because I wasn't sure which browsers you were going for (although given the filter I'm guessing 5.x+ of IE atleast).

Anyway hope that helps.