Introducing iframe elements on v2
See original GitHub issueSince I’m planning to switch to v2 soon, I’m preparing a major update of our apps and I tried v2.0.0-beta2
: suddenly a wild iframe
appeared in the DOM (causing issues with AdBlock, BTW).
Is v2 really introducing an iframe
element when drawing graphs?
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (8 by maintainers)
Top Results From Across the Web
Introducing iframe elements on v2 #2210 - chartjs/Chart.js
The iframe solution works because it is set to be the same size as the canvas container node. Since the iframe is a...
Read more ><iframe>: The Inline Frame element - HTML - MDN Web Docs
The <iframe> HTML element represents a nested browsing context, embedding another HTML page into the current one.
Read more >The ultimate guide to iframes - LogRocket Blog
We'll go through most of the features the iframe element provides and talk about how you use them, as well as how iframe...
Read more >The Magical <iframe> Tag: An Introduction - EasyRotator
It is the ultimate modularization tool, allowing you to break up content, seamlessly display content from other sources, and better manage ...
Read more >4.8.2 The iframe element — HTML5 - W3C
The iframe element supports dimension attributes for cases where the embedded content has specific dimensions (e.g. ad units have well-defined ...
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
@heruan v2 is adding an iframe. The reason an iframe is added is to detect when the canvas container resizes. There is a window resize event, which was used by v1, but it only detects when the entire window resized and not a specific element. This led to the problems of charts not displaying correctly when their container was initially
display: none;
and then displayed (See #762 ).I investigated a number of solutions for implementing better resize behaviour. Almost all of the available solutions use some combination of a timer / requestAnimationFrame. Unfortunately, this is bad for mobile battery life since we have to poll the size of the container continuously and check for a change.
The iframe solution works because it is set to be the same size as the canvas container node. Since the iframe is a window, the window resize event can be listened to and then passed up out of the iframe to the chart to tell it when the container node resized.
There is some other discussion on this topic in #2024
Just to add my $0.02 on this: The hidden iframe causes some issues for me when integrating Chart.js v2 into my Echo 3-based client-side application. Specifically, the insertion of the hidden iframe just before my canvas node prevents the canvas element from rendering properly (its height and width are left unset). My workaround is to disable resize listening: