最近在ionic项目中,html中嵌入iframe标签,在ts引用时出现以下错误
[ts] Property ‘contentWindow’ does not exist on type ‘HTMLElement’.
我的html代码如下
<ion-content scroll="true" overflow-scroll="true">
<iframe
name="mainFrame" id="mainframe"
class="width-100 height-100"
style="position: absolute; min-width: 100%; min-height: 100%; z-index: 99;">
</iframe>
</ion-content>
我一开始的ts引用代码如下
document.getElementById("mainframe").contentWindow.postMessage("getPicValue:" + imageData, "*");
最后的解决方案是
let iframe = document.getElementById("mainframe");
var iWindow = (<HTMLIFrameElement> iframe).contentWindow;
iWindow.postMessage("getPicValue:" + imageData, "*");
本文介绍了一个在Ionic项目中使用iframe时遇到的问题:无法正确引用iframe的内容窗口。通过调整类型断言的方式,最终成功实现了跨窗口消息传递。

3030

被折叠的 条评论
为什么被折叠?



