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 :)
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 :)