[英]how to detect if the iframe is fully loaded in angular
Is there anyway that I can detect if the iframe is completed loading?无论如何我可以检测 iframe 是否已完成加载? This is my iframe code:
这是我的 iframe 代码:
<div ng-if="isLoadDone" class="col-xs-12">
<div class="text-center"><span class="fa fa-spinner fa-pulse fa-5x fa-fw margin-bottom"></span></div>
</div>
<iframe ng-if="isLoadDone" class="app-iframe" ng-src="{{trustedApplUrl}}"></iframe>
Basically I want to display the spinner if the iframe is not full loaded.基本上,如果 iframe 未满载,我想显示微调器。 I want to detect if iframe is completed loading not start loading.
我想检测 iframe 是否已完成加载而不是开始加载。 I was able to find the way to find out if the iframe starts loading but not when the iframe is completed loading.
我能够找到方法来确定 iframe 是否开始加载,而不是 iframe 加载完成时。 Any idea?
有什么想法吗? Thanks -Kim
谢谢 -Kim
<iframe (load)="myLoadEvent()" id="myiframe"></iframe>
In component在组件中
myLoadEvent(){
// do your task
}
This works in angular6.这适用于 angular6。 This is not to identify if iframe is fully loaded.
这不是为了识别 iframe 是否已完全加载。 But will help anyone who lands here for iframe load
但会帮助任何登陆 iframe 加载的人
I found a couple other ways to make it work with IE11 and Angular 4.我找到了其他几种方法来使其适用于 IE11 和 Angular 4。
Using Renderer2使用 Renderer2
<iframe #iframe id="iframe" name="pdfPreview" type="application/pdf"></iframe> this._rndr.listen(this.iframeRef.nativeElement, 'load', (e) => { alert("works"); }
Adding callback to window向窗口添加回调
<iframe onload="loadEvent(event)" id="iframe" name="pdfPreview" type="application/pdf"></iframe> (window as any).loadEvent = (event) => alert("works too");
您可以将ng-onload用于此类事情。
<iframe ng-onload="myLoadEvent()" class="app-iframe" ng-src="{{trustedApplUrl}}"></iframe>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.