IE9 and swffit.js

Full disclosure: I don’t know Javascript. Yes, I should learn it, but at the moment I just have a specific problem I’m trying to solve, so I’m hoping someone with the skills and/or tools to hunt down the source of it will take pity on me.

I’m using Miller Medeiros’ swffit.js script (swffit - Smart Flash Resize Script - 100% Width and 100% Height) to resize a Flash presentation. It’s misbehaving slightly in IE9, and while I can overcome that with an “X-UA-Compatible” meta tag, I’d rather not introduce hacks to accommodate a current browser.

For context, here’s where everything ends up: Vertical Scrollbar. Click the first thumbnail. Use the little drag handle at lower right to resize the window. This works perfectly in FF3, FF4, Chrome, IE7, and IE8. But in IE9, I end up with a vertical scrollbar in the window.

In that context, there are a lot of “actors” involved, including the Highslide JS expander and the JW Player. But we can eliminate those red herrings. Here’s a very stripped-down example, one that involves only swfobject.js, swffit.js, a few lines of HTML, and a boring little SWF file: SWF Fit Minimal. Change the browser window size, and you’ll see that in IE9, the vertical scrollbar never goes away, unlike the result in any other browser. For this example, I’m using the swffit.js source code rather than the packed version, to make tinkering easier. The last non-beta version of swffit.js, by the way, has exactly the same problem.

My guess is that there’s something different about the way IE9 reports the viewport size, or about the way it responds to the resized Flash object, but I don’t know how to track down those differences.

I ran this by Miller, and his suggested solution doesn’t seem to have any effect: Another minor IE9 issue - SWFFit | Google Groups. I’ve tried tinkering with that chunk of the code, but with no luck (and it would be just luck, not skill, if I stumbled on the solution).

In that thread, and in several others (Discussions - SWFFit | Google Groups), he’s made it fairly clear that a new version of swffit.js is not really on the horizon. Who can blame him? Paying clients have to come first, after all.

Anyone out there who can fix the script?


For anyone else who’s looking into this, it appears that swiffit performs browser sniffing:

IE = /msie/.test(AGENT) && !win.opera,

These are the parts of the code that are affected by such browser sniffing.

if(IE){ swfobject.addLoadEvent(initFit); } //fix conflict with swfaddress 2.3 and IE8 (in some browser modes)
st += (IE)? '; overflow:hidden' : ''; //fix IE8
//fix window innerSize difference when scrollbar is visible
iw -= (!IE && ih <= _mh)? 18 : 0;
ih -= (!IE && iw <= _mw)? 18 : 0;

Yet another example of why browser sniffing is not a good idea - it usually breaks when a new version of a browser comes out. Also that code is breaking the page just the same for anyone using any other browser where the useragent is set to identify the browser as IE rather than what it really is - as you can do in all the popular browsers.