admin管理员组文章数量:1425690
So I am loading a load screen in my app. Then I load my custom elements through HTML imports by making a link
element in JavaScript. I need to know when this HTML import has finished loading to display content to the user. Do HTML imports fire an event when the download finishes?
So I am loading a load screen in my app. Then I load my custom elements through HTML imports by making a link
element in JavaScript. I need to know when this HTML import has finished loading to display content to the user. Do HTML imports fire an event when the download finishes?
3 Answers
Reset to default 3When the HTML import has finished loading, it fires an event called HTMLImportsLoaded. I'd remend you to rely on this event to get a consistant behavior across the different browsers.
window.addEventListener( "HTMLImportsLoaded", function ()
{
//HTML Imports are loaded
} )
On HTML Imports, read this to understand the difference between onload
, HTMLImportsLoaded
and WebComponentsReady
:
http://webponents/polyfills/html-imports/
You have onload
event.
<script async>
function handleLoad(e) {
console.log('Loaded import: ' + e.target.href);
}
function handleError(e) {
console.log('Error loading import: ' + e.target.href);
}
</script>
<link rel="import" href="file.html"
onload="handleLoad(event)" onerror="handleError(event)">
For more on imports, here you go.
If you need to know when all imports are loaded you can use:
window.addEventListener('WebComponentsReady', function() {
// imports are loaded and elements have been registered
});
本文标签: javascriptIs an event fired when an HTML import finishes loadingStack Overflow
版权声明:本文标题:javascript - Is an event fired when an HTML import finishes loading? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745394794a2656764.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论