Firefox’s Zoom messes up Iframes with Flex. Here’s the fix

While working on IFrame integration for pearltrees I came across a pretty unfathomable bug that I haven’t seen documented elsewhere, so I thought I’d post about it here. Zooming in Firefox messes up IFrame positioning. Furthermore, Firefox remembers zooming for each individual page, so if perchance you zoomed in the application by accident, things will be permanently messed for that url. What it looked like at the offset was that on one computer only the Iframe would spill out of its bounds. Changing the name of the html file would somehow solve the problem. :-) Once I’d identified the problem, here’s how I solved it. The fix only works if the host Flash application uses “noscale”, and would need to be slightly adapted if the application didn’t take the whole window. The main IFrame management code is inspired from this.

The first step is to detect zooming. I drew inspiration from this post to write the following:

In the loading file I added a simple function to get the browser width:

function getInnerWidth(){

return innerWidth;

}

Using this function and the stage width I can deduce the zoom factor and apply it to my IFrame to size and position it :

/**

* Adjust frame position to match the exposed area in the application.

*

*/

public function moveIFrame(): void{

var localPt:Point = new Point(0, 0);

var globalPt:Point = this.localToGlobal(localPt);

var innerWidth:Number = ExternalInterface.call(“getInnerWidth”);

var browserScaling:Number = 1;

if(innerWidth > 0){

browserScaling = innerWidth / Application.application.width;

}

ExternalInterface.call(“moveIFrame”, frameId, iframeId, globalPt.x * browserScaling, globalPt.y * browserScaling, this.width * browserScaling, this.height * browserScaling);

}

Finally, when should this resizing occur? On loading, obviously, but also when the user resizes during the session. So in the Iframe constructor I added the following callback that can be called from Javascript:

ExternalInterface.addCallback(“refreshIFrame”, moveIFrame);

Then I added the following event listener on the body element of the HTML container:

onresize=”document.getElementById(’Main’).refreshIFrame()”

Voilà! On the fly adaptation to a user zoom when using an Iframe in Flex. Added points would be for re-dimensioning the Iframe during the mouse scroll, but at least for now this is more than enough for my purposes.

Update: Of course, talk is nice, a working example is appreciated. Here we go

11 Responses to “Firefox’s Zoom messes up Iframes with Flex. Here’s the fix”

  1. lexa says:

    Hi
    this is interesting
    have you an online example so I can figure out how efficient it is?

  2. lexa says:

    and how precise :-)

  3. lexa says:

    it works great!
    perfect in fact
    i would suggest you also provide a sample without your solution so that people can see the bug
    but anyway i experienced it. and by the way i do have an example : on http://flashcms.fr/flash-website/dynamic-flash/agenda.evenements/agenda.google if you change firefox zoom, it happens
    thanks for this solution
    lex.

  4. [...] came across a unique Firefox issue – the zoom feature messes up the iframes with Flex – and discovered a fix. I hope you’ve read his interview about Pearltrees on Flex [...]

  5. Nash says:

    It seems iFrame messup in IE-8 too when zoom feature is used. i observed this in the link lexa provided above.

    One more interesting issue observed, when zoom reverted back to initial 100% frame doesn’t come back to original until user toggle to some other screen and back to first screen.

  6. admin says:

    Hi Nash,
    yes, IFrames are definitively a hack. I hope browsers and plugin developers figure this out, becuase there is definitively a demand for this.
    bye
    Ariel

  7. Julien N says:

    Hi Ariel, nice solution !
    I integrated it in the Flex-IFrame project (http://code.google.com/p/flex-iframe/ ). I made little modifications to avoid recalculating the zoom ratio too often, and to make it work on IE, FF, Chrome, Safari and Opera.
    Thanks for your fix !

    Cheers ;)

  8. admin says:

    Hi Julien,
    I’m glad it can be of use!
    bye
    Ariel

  9. Tobias says:

    Hey! This seems like the solution to my problems, I’ve made a dynamic xml slideshow in Flash CS3 that get messed up as you zoom.

    The thing is: I have no idea what Flex is nor have I ever used it so my question is wether you can (and how you do to) use it in just a normal Flash (.fla) file?

    Thank you, seems great eighter way :)

  10. admin says:

    Hi,
    the fix is not at all Flex specific, you should be able to apply this to a flash project without any problems.
    bye
    Ariel

Leave a Reply