...

View Full Version : Script doesn't work in IE?



spl1nter
09-07-2006, 10:55 PM
I'm new to JS but I think I'm picking it up not too bad. This problem has perplexed me. I'm trying to use Prototype and Scriptaculous:


var gameInfo = Class.create();

gameInfo.prototype = {

initialize: function() {
if (!document.getElementsByTagName){ return; }
var anchors = document.getElementsByTagName('a');

// loop through all anchor tags
for (var i=0; i<anchors.length; i++){
var anchor = anchors[i];

var classAttribute = String(anchor.getAttribute('class'));

if (anchor.getAttribute('href') && (classAttribute.match('gameTitle'))){
anchor.onclick = function () {myGameInfo.start(); return false;}
}
}
},
start: function() {
new Effect.toggle($('gameInfo'), 'slide');
}

}

function initGameInfo() { myGameInfo = new gameInfo(); }
Event.observe(window, 'load', initGameInfo, false);
I'll admit, I've based a lot of this code on Lightbox2.0 but it does something much simpler.

If you go to this (work-in-progress) page (http://psf.gamehideout.co.uk/dah.php) and click on "Destroy all Humans!" you'll see what I'm trying to acheive. Of course, you need to use Firefox or Opera (hopefully Safari as well. Can anyone confirm?) as it doesn't work in IE.

I know I could get that effect without the above code but I needed it to degrade gracefully. This way people without JS can view the same content but on another page (doesn't work yet as the site is very incomplete).

If anyone can shed light on why this doesn't work in IE I'd be very grateful :)

_Aerospace_Eng_
09-07-2006, 11:06 PM
I would do this part differently.

for (var i=0; i<anchors.length; i++){
var anchor = anchors[i];

var classAttribute = String(anchor.getAttribute('class'));

if (anchor.getAttribute('href') && (classAttribute.match('gameTitle'))){
anchor.onclick = function () {myGameInfo.start(); return false;}
}
}
Instead of that I would do

for (var i=0; i<anchors.length; i++){
var anchor = anchors[i];

if (anchor.getAttribute('href') && anchor.getAttribute('class') == 'gameTitle'){
anchor.onclick = function () {myGameInfo.start(); return false;}
}
}

spl1nter
09-07-2006, 11:12 PM
Thanks :) Always nice to have more concise code.

Unfortunately it doesn't fix the problem.

spl1nter
09-08-2006, 12:43 AM
OK, I've been through the code and found out where it goes wrong:


if (anchor.getAttribute('href') && anchor.getAttribute('class') == 'gameTitle'){

IE says that's false and when it should be true.

_Aerospace_Eng_
09-08-2006, 12:51 AM
Okay IE tends to have problems with getAttribute for certain attributes. Try

anchor.getAttribute('href') && anchor.className == 'gameTitle'

spl1nter
09-08-2006, 01:01 AM
Cheers :D

Works great! Kinda...

The script works...but actually crashes IE. At least, it crashes my IE. Can someone else confirm this for me? The page is here (http://psf.gamehideout.co.uk/dah.php).

spl1nter
09-08-2006, 02:11 AM
Actually, it has nothing to do with this script.

Seems to be a problem with the slide animation in Scriptaculous. It works perfect when using blind instead.

_Aerospace_Eng_
09-08-2006, 05:06 AM
Get your coding up to par before you trying making it do 'cool' things.
You have a few errors that need to be fixed. See them here (http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fpsf.gamehideout.co.uk%2Fdah.php).

spl1nter
09-08-2006, 05:13 PM
None of those errors are major. This is only a test page at the moment and not public. Trust me, when I've sorted everything out I will go through the errors. But that showed no reason why my code fails. In fact, it's nothing to do with my code but in fact a reported bug in scriptaculous.

It's been fixed in the latest version of Scriptaculous :)

_Aerospace_Eng_
09-08-2006, 07:59 PM
I know. I'm just saying I don't see your logo in IE6. It seems to show up briefly then it disappears.

spl1nter
09-08-2006, 09:24 PM
Oh, well I didn't know that as you never said :)

I'm currently using a 24-bit PNG with alpha-transparency which, of course, IE6 doesn't support so I used a JS hack to get around this. It's worked in everyone elses IE6 that I've spoken to. Anyway, that'll be gone in the final version because I don't need to use a PNG anymore. A GIF will do (in previous versions the background changed depending on the page but I've decided to have just the blue bar now).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum