最近在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, "*");