javascript - 在 IFrame 上加载,使用 Angular 2+
问题描述
每次我的 iframe 导航到另一个 url 时,我都需要放置一个加载器。我认为这是可能的,逻辑如下:
onLoad(Iframe: ElementRef) {
this.Hide();
}
onNavigate(Iframe: ElementRef) { // this event does not exist
this.show();
}
有人知道如何制作吗?
解决方案
iframe 上没有导航事件,您只能在 src 属性更改时获得初始加载。因此,如果 iframe 中运行了 SPA,则需要手动检索它:
我建议您使用 ngAfterViewCheck 并像这样检索位置
this.iframeLocation = iframeRef.nativeElement.contentWindow.location.href;
主要问题:如果 iframe 是跨域的,浏览器将不允许您获取位置。
推荐阅读
- asp.net - NLog:根据记录器名称和 Quartz 日志分组写入两个不同的目标
- javascript - Material UI + React Form Hook + 多个复选框 + 默认选中
- mongodb - 根据发布版本排序,即;美国广播公司
- python - 我想知道为什么会出现这个错误,IndexError: list index out of range
- javascript - 字体真棒图标不对齐
- ssl - Qualsys 漏洞 SSL 证书 - 签名验证失败漏洞
- google-colaboratory - 如何在 Google Colab 上使用 Python 2?
- python - 将 Python np.expand_dims 翻译成 R
- java - JGraphT - 通过某些特定顶点查找路径的库算法
- c++ - 随着时间的推移,如何在 OpenGL 中平移和旋转三角形?