我动态创建了一个iframe,发现这个iframe触发onload事件两次.
var i=0;
frameOnload=function(){
console.log(i++);
};
var ifr=document.createElement("iframe");
ifr.src="javascript:(function(){document.open();document.write('test');document.close();})();";
ifr.onload=frameOnload;
document.body.appendChild(ifr);
Run Code Online (Sandbox Code Playgroud)
为什么我终于是1?
如何防止iframe的onload两次而不是将onload函数指向null本身?
我想在角度2打字稿中更改iframe内部元素的属性,类似于javascript代码
document.getElementById('iframeId').window.document.getElementById('home-grid').style.visibility = "hidden";
我的Angular打字稿代码:
var iframe = document.getElementById('iframeId');
var insideDoc = iframe.contentDocument || iframe.contentWindow.document;
Run Code Online (Sandbox Code Playgroud)
编译代码时出错:
stream.js:74
throw er; // Unhandled stream error in pipe.
^
Error: ./angularapp/web/component/mainPage/mainPage.ts
?[37m(?[39m?[36m35?[39m,?[36m32?[39m): ?[31merror TS2339: Property 'contentDocument' does not exist on type 'HTMLElement'.?[39m./angularapp/web/component/mainPage/mainPage.ts
?[37m(?[39m?[36m35?[39m,?[36m58?[39m): ?[31merror TS2339: Property 'contentWindow' does not exist on type 'HTMLElement'.?[39m
Run Code Online (Sandbox Code Playgroud)
有没有办法在角度2中实现这一点?请帮忙