PDA

View Full Version : Problem with a Javascript in Internet Explorer when Lightbox is on the same page...



barbapappa
02-15-2008, 09:13 AM
1) Script Title:
Lightbox image viewer 2.03a

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex4/lightbox2/index.htm

3) Describe problem:

I have a page were I won't to use Lightbox together with Tab Content Script.
Because I don't have the possibility to work around in all the code (it's a system with locked code) I have to use a Javascript so I can change some words on all places at the same time.
That script is in the quote:


setTimeout("Init()", 1)

function Init() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(i in arrTxt){
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}
}



The problem is that it don't work in Internet Explorer. It works fine in Firefox.
If I delete the prototype.js in Lightbox it also works in Internet Explorer. So it's something in Lightbox/prototype.js that is incompatible with my quoted script when used in IE.
The question is what?

Here is a link to a zip-archive with the files and images
http://www.megaupload.com/?d=6PF39O6R

jscheuer1
02-15-2008, 10:28 AM
You may have better luck doing it this way:


function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(var i=1;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

setTimeout("Initstuff()", 1)

barbapappa
02-15-2008, 05:51 PM
You may have better luck doing it this way:


function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(var i=1;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

setTimeout("Initstuff()", 1)

No, that one do so the "t1t" won't be seen in Firefox either.

jscheuer1
02-15-2008, 06:51 PM
Works here with your demo download, but this is even better:


function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(var i=1;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

window.onload=Initstuff;

barbapappa
02-15-2008, 09:51 PM
Works here with your demo download, but this is even better:


function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(var i=1;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

window.onload=Initstuff;

Hmm, I can't get it to work properly.
I include a print screen so you can see how it looks like on my screen.
I'm missing text on the first tab, both with and without active and hover.
But it's a progress from before when it was totally blank in IE... :)

jscheuer1
02-16-2008, 01:19 AM
Here's the archive I downloaded rezipped. The only changes are its name, the name of its root folder, the removal of the two largest images, and the modifications to the ers.js file:

1596

barbapappa
02-16-2008, 07:34 AM
Ok, I've missed to get rid of a link to a backgroundpic in tabcontent.css that I've used instead of the Javascript to show text on the tabs.
After I have adjusted that I think you will se that the first tab is missing text.

Se my attachment below:

jscheuer1
02-16-2008, 08:24 AM
function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(var i=0;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

window.onload=Initstuff;

Works. But, if you want to preserve the divisions, use:

var arrObj=new Array("t1d","t2d","t3d");

instead of:

var arrObj=new Array("t1t","t2t","t3t");

barbapappa
02-16-2008, 10:30 AM
function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(var i=0;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

window.onload=Initstuff;

Works. But, if you want to preserve the divisions, use:

var arrObj=new Array("t1d","t2d","t3d");

instead of:

var arrObj=new Array("t1t","t2t","t3t");

Thank you very much for your patience ... :) ... but I wonder if we are looking at the same code.

1.)
If I use this in ers.js I got the result I presented above (in the included image-file) in Firefox and with Internet Explorer after security warnings. If I publish it on the net it doesn't work at all in IE:

function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(var i=1;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

setTimeout("Initstuff()", 1)

2.)
If I use this instead I got all tabs with text in Firefox, but it don't work in Internet Explorer:


function Init() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1t","t2t","t3t");
for(i in arrTxt){
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}
}

setTimeout("Init()", 1)


3.) Now, if we take the 2.) - code and also take away the link in index.html to prototype.js it also work in Internet Explorer *yes*. I do have a warning triangel down in left corner. But it works...

The question is what. It's the same if I use setTimeout or window.onload.

jscheuer1
02-16-2008, 04:17 PM
The code I am looking at is the code I downloaded from the link you provided. It is the same as the code I made available in my attached zip post. The setTimeout is a bad idea. It assumes that the elements required by the script will be ready at an arbitrary point 1 millisecond after the setTimeout is called. Also, the for(i in arrTxt){ is a bad idea. There could be other i in arrTxt than just its array items, and i is in the global scope, so may not be empty at the beginning of the loop.

What version(s) of IE are you using? If you have a live page that demonstrates the problem, please provide a link to it.

Also, from your last post, it looks like you haven't updated this line:

for(var i=0;i<arrTxt.length;++i)

as indicated in my previous post - though this shouldn't have anything to do with an error, just to do with what elements get updated.

barbapappa
02-17-2008, 10:07 AM
The code I am looking at is the code I downloaded from the link you provided. It is the same as the code I made available in my attached zip post. The setTimeout is a bad idea. It assumes that the elements required by the script will be ready at an arbitrary point 1 millisecond after the setTimeout is called. Also, the for(i in arrTxt){ is a bad idea. There could be other i in arrTxt than just its array items, and i is in the global scope, so may not be empty at the beginning of the loop.

What version(s) of IE are you using? If you have a live page that demonstrates the problem, please provide a link to it.

Also, from your last post, it looks like you haven't updated this line:

for(var i=0;i<arrTxt.length;++i)

as indicated in my previous post - though this shouldn't have anything to do with an error, just to do with what elements get updated.

Back...

Now I have uploaded 2 pages with, one with the code that you prefer and one with the original code.

1.) http://snusmumrik.webs.com/index.html

Your code: With this one I have no text on the first tab (I did a miss in my first uploaded page and had a link in tabcontent.css with a pic with text). No that is gone. It seems to work in IE to but with the same text missing in the first tab.

2.) http://snusmumrik.webs.com/index_bad.html

My original code: With this one I'ts correct in Firefox with text on all tabs but it's blank on Internet Explorer. I have tested that with both 6 and 7 IE...

jscheuer1
02-17-2008, 10:35 AM
That's not the code I prefer, use:


function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1d","t2d","t3d");
for(var i=0;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

window.onload=Initstuff;

With a 0 not that 1 you have, and that I had at first. Are you color blind? I mean no disrespect, just curious.

barbapappa
02-17-2008, 11:50 AM
That's not the code I prefer, use:


function Initstuff() {
var arrTxt=new Array("Beskrivning","Specifikationer","Dokument, lšnkar...");
var arrObj=new Array("t1d","t2d","t3d");
for(var i=0;i<arrTxt.length;++i)
if(document.getElementById(arrObj[i])&&arrTxt[i])
document.getElementById(arrObj[i]).innerHTML=arrTxt[i];
}

window.onload=Initstuff;

With a 0 not that 1 you have, and that I had at first. Are you color blind? I mean no disrespect, just curious.

He he, I've missed that you changed from 1 to 0. I thought that you mean that I should use your code and not my old one with the yellow background. :p I should perhaps looked once more...

It look's like it works now! :) I have tried it on both IE 6 and 7.

http://snusmumrik.webs.com/index_js.html

Thank's again for your patience with a slow newbie!

Just for curious:
Why do I get a security warning (that I can confirm) in IE when it's on my local computer, but when I uploaded on the net and look it works correct directly?

jscheuer1
02-17-2008, 12:29 PM
Just for curious:
Why do I get a security warning (that I can confirm) in IE when it's on my local computer, but when I uploaded on the net and look it works correct directly?

This is a security feature of IE, starting with v 6 service pak 2. The reason for it is simple. Pages running on the local system have access to your computer's entire drive structure, so if malicious code were present, it would have an easy time running programs and otherwise messing things up on your local system, much easier than a page on the internet would. This warning used to be easily avoided by using a special comment in the head of the file, but starting with v 7 even this has been eliminated, as it really negated this protection. It is only a warning though, so make sure, before you click 'yes' or 'OK' or whatever, that you trust the content that you are about to run locally.

Incidentally, once you have a tab (or a window, in the case of IE 6) allowing 'Active Content', you can load other local pages that use javascript into it with no warning.