Syndicate content

jQuery and hidden IFRAME bug

In the last 3 days I've been working on a new page and ran in some strange problem. There was an error in the console but things seemed to otherwise work just fine so I ignored it (since it wasn't in my own code...)

That error was an unhandled jQuery error which resulted in "let's stop the JavaScript at once." This meant all the page initialization failed (or did not occur.) The code was there otherwise. What give?!

The script in question was loaded from a hidden IFRAME, something like this:

  <div style="display: none;">
    <iframe src="/my-iframe"></iframe>
  </div>

The jQuery script in the IFRAME would fail because it couldn't find a valid computed style for some of the elements in the IFRAME. This is because FireFox does not compute those elements' geometry until the IFRAME is computed and therefore the getComputedStyle() returns NULL.

This is fixed since jQuery 1.6.1, but unfortunately with Drupal I'm currently stuck with 1.5.2. So I had to implement the fix myself in my 1.5.2 version. If you have another version of jQuery older than 1.6.1, the fix is the same, just the location may be completely different. The fix looks like this:

jquery.js (jQuery 1.5.2)

(a) search for "reliableMarginRight = "
(b) add an opening parenthesis after "parseInt("
(c) add " || { marginRight: 0 } )" after "null )"

  if ( document.defaultView && document.defaultView.getComputedStyle ) {
    div.style.width = "1px";
    div.style.marginRight = "0";
// Note: cut the following on two lines so it works on the website.
    jQuery.support.reliableMarginRight = ( parseInt( ( document.defaultView.getComputedStyle(
                     marginDiv, null ) || { marginRight: 0 } ).marginRight, 10) || 0 ) === 0;
  }

jquery.min.js (jQuery 1.5.2)

(a) search for the second getComputedStyle
(b) add an open parenthesis before the "c.default"
(c) add "||{marginRight:0})" after the "null)"

  parseInt((c.defaultView.getComputedStyle(a,null)||{marginRight:0}).marginRight,10)

Bug report: http://bugs.jquery.com/ticket/8763
Fix (click on Diff): https://github.com/jquery/jquery/pull/370/files

Reply to comment | The Linux Page

You need to take part in a contest for one of the highest quality blogs
on the internet. I'm going to recommend this web site!

Syndicate content

Diverse Realty

Diverse Realty Team

Want a New Home?
Want to Sell Your House?

Call Alex at
+1 (916)
220 6482

Alexis Wilke, Realtor
Salesperson
Lic. # 02024063

Cory Marcus, Broker
Lic. # 01079165

     

Terms of Site Index

Find the page/content you are looking for with our index.

  • DVD
  • float

    float is a type in most software languages referencing an IEEE floating point number. These numbers are generally defined on 32 or 64 bits with three parts: a sign, an exponent and a mantissa. There is also a bias which is not saved in the number. The sign is 0 (positive) or 1 (negative). This means you have a representation of: +0.0 and -0.0. The exponent is about 1/6th the total size in bits. The bias is added/subtracted from the exponent. In the end, it is a signed power of 2 exponent (i.e. exercises a shift on the mantissa.) The mantissa forms the current number.

  • OpenOffice
  • parameter
  • Safari