firefox: style tags in hidden iframes do not apply css
See original GitHub issueIssue Description
This is for the feature/curriculum-expansion branch only when run locally, and NOT the staging branch.
For several challenges (challengeType: 0, using the code editor with the mobile-phone output layout), the jQuery method .css() doesn’t seem to be accessing the styles applied in a style
tag in the given code. This is affecting any assert tests that use a pattern of assert($('selector').css('propertyToCheck') == 'valueToCompare', 'message: ...');
.Here’s an example:
<style>
h2 {
position: relative;
top: 15px;
}
</style>
<body>
<h1>On Being Well-Positioned</h1>
<h2 class="testCode">Move me!</h2>
<p>I still think the h2 is where it normally sits.</p>
</body>
<script>
console.log($('h2').attr('class')); // Works great, returns testCode
console.log($('h2').css('position')); // returns undefined
console.log($('h2').css('top')); // returns undefined
</script>
Related assert tests that aren’t passing:
assert($('h2').css('position') == 'relative', 'message: Add a CSS rule to specify that the <code>h2</code> has a <code>position</code> set to <code>relative</code>.');
assert($('h2').css('top') == '15px', 'message: Use a CSS offset to relatively position the <code>h2</code> 15px away from the <code>top</code> of where it normally sits.');
Browser Information
- Browser Name, Version: Firefox 48.0.1
- Operating System: Mac OS X, El Capitan v10.11.3
- Mobile, Desktop, or Tablet:
Issue Analytics
- State:
- Created 7 years ago
- Comments:22 (20 by maintainers)
Top Results From Across the Web
Iframe in firefox loads css before js and breaks styling
If you right-click the iframe and go to ThisFrame dialog and click ReloadFrame, you will be able to see the proper style now....
Read more >1079486 - CSS attribute not available in JS in hidden IFrame
Issues with loading CSS style sheets from the network, parsing style sheets and style attributes in HTML markup, performing the CSS cascade, selector...
Read more ><iframe>: The Inline Frame element - HTML - MDN Web Docs
The HTML element represents a nested browsing context, embedding another HTML page into the current one.
Read more >Hidden iframe is not able to calculate the content's scrollHeight
scrollHeight read-only attribute is a measurement of the height of an element's content including content not visible on the screen due to overflow....
Read more >window.getComputedStyle() returns null inside an iframe with ...
If you're display:none then the information needed to compute style (which medium is in use, the size of the CSS viewport, the zoom...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We run tests in a separate hidden iframe is to get around a whole host of issues with running user code multiple times for tests.
In the future I would like to run each tests in it’s own environment, so this would not be a solution.
Alternatively we could try hiding the iframe in another fashion, such as making it
position: absolute; top: -9999999999999, left: -999999999;
and putting it in zero width div with overflow hidden. Would this get around that issue?@QuincyLarson Can you elaborate on how not pulling in the libraries is the underlying issue here? Seeing as though it works fine in Chrome, and other jQuery tests (as long as they don’t involve the
.css()
method).I looked into the issue a bit, and here’s what I found: There’s an open issue over at the jQuery repo: https://github.com/jquery/jquery/issues/3514 The underlying Firefox issue: https://bugzilla.mozilla.org/show_bug.cgi?id=548397 In summary, we can’t get the styles in Firefox from
display: none;
iframe. The reason why this isn’t a problem on the live site is that on there, tests are being run in the visible iframe, rather than an iframe specifically for the tests. @BerkeleyTrue Would running tests in the visible iframe be possible in the beta? Could that be a solution?There’s a caveat with @Greenheart’s suggested solution. Though I’m a big fan of vanilla JavaScript, it won’t save us here. Using the style property is not the proper way to get the style: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#Getting_style_information I put together a little demo to demonstrate the difference between the two: http://codepen.io/systimotic/pen/ryLJBy?editors=1011
getComputedStyle
would also not help, as it has the same issue as the jQuery solution. Interestingly, I couldn’t get the.style
tests to work in any browser. This may indicate that I did something wrong in my demo. @Greenheart any input?I’d love to get this working quickly. The amount of issues we’ve had on this is insane.