I’ve discovered a bug in IE8.
It’s definitely a browser bug, as I shall demonstrate.
If you are using @font-face for your main site, and for your iframe, then you may find that the font-face is removed and replaced with arial or helvetica when the iframe is removed from the page. This is a common effect of modal iframe lightbox systems, like shadowbox or thickbox.
My assumption is that the iframe is ‘stealing’ the font-face EOT file, and killing references to it when the iframe is removed. This affects the main page.
In tests, I’ve found that this effect depends on both the cache and the element with focus when the iframe is removed. This dependance (especially on the cache) makes this effect quite hard to reliably reproduce.
Interestingly, the effect does not cause a repaint of the page. You need to scroll or move a window over the top to cause a repaint, revealing the unstyled text. Note also that it is the font rendering that has changed, but not the letter positioning – causing our ‘unstyled’ font to look even worse than plain text.
As promised, a demo:
You’ll need IE8. You want this page to be cached (try refresh, but not ctrl-refresh, with cache status as automatic). Note that the ‘kill frame’ link below does not return false.
Click this link to kill the iframe.
Now resize the window to try and trigger a repaint.
(This effect is quite unreliable, so you may need to refresh and kill a few times to see it happen. If you just can’t Click here for a screenshot)
My workaround solution is to reload the main page stylesheet after the box is closed.
Hardly pretty, but it should work. I’ll leave it to the hardcore CSS/JS fraternity to try and reload the font-face lines themselves.
Add an ID to your stylesheet tag:
<link id="main-css" rel="stylesheet" type="text/css" href="/css/styles.css" />
Then, after your box closes, reload it:
document.getElementById('main-css').href=document.getElementById('main-css').href;
//or in jQuery
$('#main-css')[0].href=$('#main-css')[0].href;
Additional:
Make sure your iframe doctype matches the container. It’s possible that if they don’t match, then only one will show the fonts.
Pingback: IE8 web font iframe bug workarounds | SeekPHP.com
Pingback: Meredith Dodge - @font-face problem with Facebook in IE8