Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Scotis opened this issue May 6, 2014 · 9 comments
Closed

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

Scotis opened this issue May 6, 2014 · 9 comments
Labels

Comments

@Scotis
Copy link
Contributor

Scotis commented May 6, 2014

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];"

@davidjbradshaw
Copy link
Owner

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

@Scotis
Copy link
Contributor Author

Scotis commented May 6, 2014

Yes - I can do that later today...

@davidjbradshaw
Copy link
Owner

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;

@Scotis
Copy link
Contributor Author

Scotis commented May 6, 2014

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

@davidjbradshaw
Copy link
Owner

Yeah why not.

Also do you fancy writing a qUnit test for this?

@Scotis
Copy link
Contributor Author

Scotis commented May 6, 2014

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

@davidjbradshaw
Copy link
Owner

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.

@Scotis
Copy link
Contributor Author

Scotis commented May 6, 2014

Hmm ok I'll look into it...

@davidjbradshaw
Copy link
Owner

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants