davidjbradshaw / iframe-resizer

Keep iFrames sized to their content.

Home Page:https://iframe-resizer.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: document.defaultView.getComputedStyle(...) is null

Scotis opened this issue · comments

I get the following error in Firefox 29:

"TypeError: document.defaultView.getComputedStyle(...) is null"

The iframes I am resizing are created dynamically on the page with javascript and are inside a div that has "display: none" - so they are not visible when they are created (I do this because I want to animate the reveal of the iframe's content).

I tracked this problem down to line # 283 in iframeResizer.contentWindow.js:

"retVal = document.defaultView.getComputedStyle(el, null)[prop];"

I have fixed the problem by changing it to:

"retVal = document.defaultView.getComputedStyle(el, null);
if(retVal == null) retVal = {marginTop: 0, marginBottom: 0};
retVal = retVal[prop];"

Cool do you want to send me a pull request with the fix.

Yes - I can do that later today...

Thanks, now that I'm back home I'm wondering if it could that be reduced down to.

retVal = document.defaultView.getComputedStyle(el, null);
retVal = (null !== retVal) ? retVal[prop] : 0;

Yeah - that is probably better. Would you like me to update the pull request?

Yeah why not.

Also do you fancy writing a qUnit test for this?

Ok pull request has been updated. I haven't written a qUnit test before... is it easy to learn how?

Yeah it's pretty straight forward, have a look at the html files in the test folder for some examples, the _init.html is the simplest one.

I think you could strip that back to the first assertion that test it got a message back and the create a new iframe contents html page in the resource folder with a simple version of the page that was creating the problem.

Once you've done that you can just run 'grunt' and it will automagically run the test along with all the other ones.

Hmm ok I'll look into it...