SVG icons injected by innerHTML do not raise "onload" event
Reported by
andreas....@gmail.com,
Jun 1 2016
|
||||||
Issue description
Chrome Version : 49.0.2623.75 (Official Build) m (32-bit)
URLs (if applicable) :
Other browsers tested:
Add OK or FAIL, along with the version, after other browsers where you
have tested this issue:
Safari: FAIL Safari 9.11 (MacOS 10.11.5)
Firefox: OK Firefox 45 (Windows 7)
IE: OK IE 11 Win (Windows 7)
What steps will reproduce the problem?
(1) Load attached HTML file "the.html" in Chrome browser
(2) See that the SVG loaded initially in the HTML raises onload event
(3) See that the SVG injected by "innerHTML" does not raise onload event
What is the expected result?
The SVG injected by "innerHTML" schould raise "onload" event after being injected like an IMG is doing it.
What happens instead?
No event is raised
Please provide any additional information below. Attach a screenshot if
possible.
See here the HTML example as plain text
<!DOCTYPE html>
<html>
<head>
<script>
function inject() {
document.getElementById("Inject").innerHTML = '<svg onload="logMessage(\'Loaded Injected SVG\')" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 512" width="20" height="20"><path d="M499 183l-141 121 78 208-182-124-181 124 73-207-146-122h185l69-186 62 186h183zm-134 236l-48-130 87-75h-113l-39-116-43 116h-115l91 76-46 129 113-77z"/></svg>';
}
function logMessage(sMessage) {
document.getElementById("MessageLog").innerHTML += sMessage + "<br/>";
}
</script>
</head>
<body onload="inject()">
<svg onload="logMessage('Loaded Initial SVG')" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 512" width="20" height="20"><path d="M499 183l-141 121 78 208-182-124-181 124 73-207-146-122h185l69-186 62 186h183zm-134 236l-48-130 87-75h-113l-39-116-43 116h-115l91 76-46 129 113-77z"/></svg>
<div id="Inject">
</div>
<div id="MessageLog">
</div>
</body>
</html>
,
Jun 2 2016
Hi, thanks for the insight. I) a)The SVG embedded in the initial HTML raises an onload event. b)The SVG injected by innerHTML does not. Both do not refer to external resources. I would expect an symmetric behavior. From you explanation both should not raise an onload event, right? If you are not able to remove the onload notification for a) because of compatibility reasons, from my point of view it would make sense to introduce it in b) II) Actually the testcase was a bit simplified. Our actual usecase is to load an SVG from a symbol library in this format: <svg onload="notifyOnload(this)"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="./svgSymbolLib.svg#star"></use></svg> which is an external resource and we need to get notified when it is loaded. Any suggestions how to achieve that? Many thanks for the fast processing.
,
Jun 2 2016
I looked at how this is currently handled in Blink, and realized that it likely was intended to dispatch a 'load' for this case. Or rather there are some oddities like:
document.body.innerHTML = '<svg onload=alert("bar")><svg onload=alert("foo")></svg></svg>';
Which will alert "foo" but not "bar".
For your case with <use>, we will dispatch 'load' for the <use> element in this case (since it is "structurally external"). Firefox for instance will not though (only does that for <svg>.) Another thing to be aware of with <svg onload> is that'll be dispatched when the end tag (</svg>) has been parsed, so it doesn't really make any guarantees as to the readiness of the subtree rooted at the <svg>.
,
Jun 3 2016
Our use case is to inline an external SVG symbol libray in the document on demand to achieve some better CSS theming behavior. Actually <use>.onload works perfect for this scenario. Thanks for that hint. As you described Firefox is propagating the event only for the <svg> while IE raises it additionally for <use> as well. Safari seems to propagate the “load” on <use> element twice (parsed and external resource loaded?).
,
Jun 5 2017
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue. Sorry for the inconvenience if the bug really should have been left as Available. If you change it back, also remove the "Hotlist-Recharge-Cold" label. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Jun 5 2017
,
Jun 5 2018
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue. Sorry for the inconvenience if the bug really should have been left as Available. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Jun 5 2018
|
||||||
►
Sign in to add a comment |
||||||
Comment 1 by f...@opera.com
, Jun 2 2016