views:

1051

answers:

1

This is my first jQuery script, which works great in Firefox and Chrome, but fails in Internet Explorer.

I load two scripts using my theme's .info file:

scripts[] = jquery.jfeed.pack.js
scripts[] = script.js

The first script is a jquery plugin that parses rss feeds for me. The second script looks like this:

var init = jQuery.getFeed({
    url: 'panorama.xml',
    success: 
    function(feed)
    {
      var image = feed.items[0].description;
      $('#page').css('background-attachment', 'fixed');
      $('#page').css('background-image','url('+image+')');
      $('#page').css('background-position', 'center 63px');
      $('#page').css('background-repeat', 'no-repeat');
    }
});

$(document).ready(init);

The effect is that an rss feed containing the path to a random image in the item's description is used to set the background of the div #page. The rss feed is generated by the cck and views module. This required some additional template customization, but it works.

Everything looks great except with IE. I have tried using the Microsoft Script Debugger, but it isn't very helpful (or I don't know how to use it). There is one runtime error which looks like it may be related to google analytics code (this only started appearing more recently):

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0) Timestamp: Sun, 9 Aug 2009 19:58:39 UTC

Message: 'a' is null or not an object Line: 1 Char: 1 Code: 0 URI: http://webdev/sites/default/files/js/js_77589ce906350e35d2f4994348346ad7.js

But beyond that, when I look in the debugger I see that the jQuery code I intended to run is commented out:

;eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+
<-- snip -->
;  var init = jQuery.getFeed({
      url: 'panorama.xml',
      success: 
      function(feed)
      {
        var image = feed.items[0].description;
        $('#page').css('background-attachment', 'fixed');
        $('#page').css('background-image','url('+image+')');
        $('#page').css('background-position', 'center 63px');
        $('#page').css('background-repeat', 'no-repeat');
      }
  });

$(document).ready(init);

I have verified that this is broken in IE8 and IE6. Can any of you help me understand what is wrong here? I'm still worried about what will happen in browsers that don't have javascript enabled, but I figure it's a moot point if this won't even run in IE.

I seem to have come up with a very hacked together solution to get the effect of a random background image. I originally just displayed the image in-line, but it needs to be wider than the page without creating scrollbars. Are there any alternatives to this javascript madness?

A: 

What version of jQuery are you using. You maybe having version incompatabilities with the external script you are using (I see it is a packed version which says to me it is quite old) and if you are running jQuery 1.3.2.

Could you explain the versions and give the url's to the plugins you are using.

If you can put the page online and use the full versions of scripts it is much easier to debug and spot issues. Packed script is impossible to debug.

redsquare
I have set up port forwarding to my development box, which will be up temporarily. You can see it here: http://69.141.58.30/I'm using drupal 6.13It comes with jQuery 1.2.6, I believeHere is the url for jFeed: http://www.hovinne.com/blog/index.phpHope this helps!
Arosboro
or rather, http://plugins.jquery.com/project/jfeed
Arosboro
your adding a doc ready statement to call init. When that gets parsed in ie init is undefined. The error you are seeing is when jQuery is trying to call the doc ready events but it cant .call(undefined)
redsquare
see the following screen grab http://gyazo.com/e17983f2c9c9f6aaeddfc1f6fadffcd9.png. You can see that init is undefined
redsquare
ok your setting the init var before the getFeed script has parsed therefore init is nothing. Try putting the getFeed script in this file or use a setTimeout to ensure it is downloaded before you set the var
redsquare
I put the contents of jquery.jfeed.pack.js on the first line before "init = Jquery.getFeed". It is still breaking though.
Arosboro
No. Your issue is you are loading the getFeed plugin with ajax I presume. You do not give the getFeed script chance to load before you start using it. When you use var init = jQuery.getFeed(...) jQuery does not know about a getFeed method.
redsquare
redsquare, thanks for all of your assistance, but I'm still confused at this point. I include jquery.jfeed.pack.js before my script--I thought this loaded the getFeed function.Can I do this without an anonymous function? I got rid of init and the styles are still applied in firefox/chrome. There is no longer an error about 'a' being undefined, but I'm not sure how to make this load in ie.
Arosboro
no it doesnt load the getFeed it is calling it. The line above that starts eval(function(p,a,c,k,e,d)e=function(c){retur...is doing a call to load the getFeed plugin script dynamically but it has not finished downloading by the time you hit your var init script
redsquare
ok now I need you to try setting cache:false inside where the getFeed plugin is doing the ajax call
redsquare
the ajax call returns a 304 in ie which means its cached and therefore wont run the success function to process the xml
redsquare
would this be easier to discuss in irc? I added 'cache: false,' to line 22 of jquery.jfeed.js under '$.ajax({'
Arosboro
irc it is then;)
redsquare
thanks, for anyone else reading -- I'll update the solution here later
Arosboro
freenode blocked mibbit;)
redsquare