1
我目前正在開發ionic2應用程序。如何從iframe觸發父窗口函數a> href click,ionic2/angular2
在一個頁面離子我已經嵌入在iframe
<iframe id="iframeId" #iframe src="./epubpages/s006-Lesson-001.xhtml" width="100%" height="100%" (load)="onLoad()"></iframe>
該頁面的.ts文件裏面
@ViewChild('iframe') iframe:ElementRef;
onLoad() {
console.log('me');
let doc = this.iframe.nativeElement.contentDocument || this.iframe.nativeElement.contentWindow;
var h = doc.getElementsByTagName('a');
console.log(this.iframe.nativeElement.contentDocument.document);
for(let i=0; i<h.length; i++){
h[i].onclick = function(){
window.parent['sayHello'];
}
}}
sayHello(){
console.log("Saying Hello from ");
}
當我點擊頁面IFRAME鏈接,該功能可按SayHello的(),這是對父頁面沒有被調用。我不知道它是否可能,但這是我的要求觸發父頁面功能。
我正在使用ionic2。
你想通了嗎?我現在有同樣的問題 –