5

I am using Cufon.replace to font replace some text on the site. Currently in IE8 standards mode when this is run outside a $(document).ready it is only happening ~50% of the time the rest of the time the DOM changes have occurred (viewing with IE8 built in dev toolbar) but no text is displayed.

Disabling the replace, and applying it manually through the console updates all the text correctly. Wrapping it in $(document).ready stops it from ever occurring - no DOM modifications (as far as I can tell from dev toolbar). However I cannot reapply manually from the console - so it may be lying to me.

Wrapping it in $(window).load seems to have the same effect as $(document).ready

Please note this only effects ie8 "Standards mode". It works fine in Firefox and IE7.

Any thoughts?

tgandrews
  • 12,349
  • 15
  • 43
  • 55
  • good point, lemme take down my answer for that. I kinda got confused when I saw the dollar sign and immediately thought that it was the main problem. Anyway, could you please paste the code so I can check? It now seems more like a timing problem and what you can do is do a check/replace every time you change the DOM(probably make a cufonRefresh method to handle this which you can call every DOM change) – corroded Sep 13 '10 at 22:05
  • @corroded - Cufon.refresh() didn't work although why I'm not sure. Is it possible that Cufon is crashing in an invalid state (when first run) and unable to remove itself try again when using refresh? – tgandrews Sep 14 '10 at 08:18
  • I'm afraid it's going to be really tough to answer this one without some code to refer to. Can you post some of your markup (specifically where you're including any JavaScript) and the JavaScript that you're trying to execute on load? – ninjascript Aug 16 '11 at 00:40

1 Answers1

1

I've experienced this before... I would wrap it in anonymous function and you can also use a simple setTimeout to delay it as well (may not be needed).

(function( $ ){ 
   // Your Cufon.replace()
   Cufon.replace('h1', { fontFamily: 'stack-overflow', hover: true });
   Cufon.now();

   // OPTIONAL - Delay by 150ms (you can experiment with this value)
   setTimeout(function(){ Cufon.refresh(); }, 150); 

})( jQuery );
Timothy Perez
  • 20,154
  • 8
  • 51
  • 39