如何从iframe a触发父窗口函数>;href单击,ionic2/angular2

如何从iframe a触发父窗口函数>;href单击,ionic2/angular2,ionic2,Ionic2,我目前正在开发ionic2应用程序 在一个ionic页面中,我嵌入了一个Iframe <iframe id="iframeId" #iframe src="./epubpages/s006-Lesson-001.xhtml" width="100%" height="100%" (load)="onLoad()"></iframe> 在page.ts文件中 @ViewChild('iframe') iframe:ElementRef; onLoad() { con

我目前正在开发ionic2应用程序

在一个ionic页面中,我嵌入了一个Iframe

<iframe id="iframeId" #iframe src="./epubpages/s006-Lesson-001.xhtml" width="100%" height="100%" (load)="onLoad()"></iframe>

在page.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 ");
}
@ViewChild('iframe')iframe:ElementRef;
onLoad(){
console.log('me');
让doc=this.iframe.nativeElement.contentDocument | | this.iframe.nativeElement.contentWindow;
var h=doc.getElementsByTagName('a');
log(this.iframe.nativeElement.contentDocument.document);

对于(让i=0;i我刚刚遇到了这一点,这可能会有所帮助。基本上,查找window.blur事件并使用它。下面是github的代码:

var myConfObj = {
   iframeMouseOver : false
}
window.addEventListener('blur',function(){
  if(myConfObj.iframeMouseOver){
    console.log('Wow! Iframe Click!');
  }
});

document.getElementById('YOUR_CONTAINER_ID').addEventListener('mouseover',function(){
   myConfObj.iframeMouseOver = true;
});
document.getElementById('YOUR_CONTAINER_ID').addEventListener('mouseout',function(){
   myConfObj.iframeMouseOver = false;
});
我在Angular2应用程序中遇到类似问题,并使用了以下方法(以防其他Angular2用户遇到此问题):

添加
'(窗口:模糊)
'(窗口:单击)
有助于处理用户单击窗口中不属于iframe的其他位置的情况


我希望这会有帮助!

我刚刚遇到了这一点,这可能会有所帮助。基本上,查找window.blur事件并使用它。下面是github的代码:

var myConfObj = {
   iframeMouseOver : false
}
window.addEventListener('blur',function(){
  if(myConfObj.iframeMouseOver){
    console.log('Wow! Iframe Click!');
  }
});

document.getElementById('YOUR_CONTAINER_ID').addEventListener('mouseover',function(){
   myConfObj.iframeMouseOver = true;
});
document.getElementById('YOUR_CONTAINER_ID').addEventListener('mouseout',function(){
   myConfObj.iframeMouseOver = false;
});
我在Angular2应用程序中遇到类似问题,并使用了以下方法(以防其他Angular2用户遇到此问题):

添加
'(窗口:模糊)
'(窗口:单击)
有助于处理用户单击窗口中不属于iframe的其他位置的情况


我希望这有帮助!

你解决了这个问题吗?我现在遇到了同样的问题你解决了吗?我现在遇到了同样的问题