Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Scotland
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script doesn't work in IE?

    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:

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

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I would do this part differently.
    Code:
    		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
    Code:
    		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;}
    			}
    		}
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Feb 2004
    Location
    Scotland
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Always nice to have more concise code.

    Unfortunately it doesn't fix the problem.
    Last edited by spl1nter; 09-08-2006 at 12:23 AM. Reason: I forgot the <span> tags which is why it didn't work with text. Works now (except IE).

  • #4
    Regular Coder
    Join Date
    Feb 2004
    Location
    Scotland
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, I've been through the code and found out where it goes wrong:

    Code:
    if (anchor.getAttribute('href') && anchor.getAttribute('class') == 'gameTitle'){
    IE says that's false and when it should be true.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Okay IE tends to have problems with getAttribute for certain attributes. Try
    Code:
    anchor.getAttribute('href') && anchor.className == 'gameTitle'
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Regular Coder
    Join Date
    Feb 2004
    Location
    Scotland
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers

    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.

  • #7
    Regular Coder
    Join Date
    Feb 2004
    Location
    Scotland
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Regular Coder
    Join Date
    Feb 2004
    Location
    Scotland
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by spl1nter; 09-08-2006 at 06:27 PM.

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I know. I'm just saying I don't see your logo in IE6. It seems to show up briefly then it disappears.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    Regular Coder
    Join Date
    Feb 2004
    Location
    Scotland
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •