从iframe触发事件 [英] trigger Event from iframe

查看:127
本文介绍了从iframe触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SharePoint站点上有两个Webparts ......基本上就像拥有两个iframe一样。我想要做的是,如果webpartA有变化,我想更新WebpartB ...我到目前为止所做的是在WebpartA我尝试触发一个自定义事件:

 $(#datain)。change(function()在Web部件商业智能中添加了一个数据库,数据库和数据库事件监听器:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ b $(#dataout)。html(data);
});

当我在WebpartA上改变某些事件时,事件被触发,但它永远不会到达WebpartB的事件侦听器。
我的代码是否有问题,或者只是不可能在两个iframe之间通过自定义事件进行通信?



感谢您的帮助。

解决方案

通过将document更改为body来修复问题
所以Webpart A是:


$ b $

  $(#datain)。change(function(){
parent。$(body)。trigger( datachange,[$(#datain).val()]);
})



  parent。$(body)。on('datachange',function(event ,data){
$(#dataout)。html(data);
});


I have two Webparts on a sharepoint site ... thats basicly like haveing two iframes . What I want to do is if there is a change at webpartA , I want to update WebpartB ... what I did so far is at WebpartA I try to trigger a custom event:

$("#datain").change(function () {
    parent.$("document").trigger("datachange" , [$("#datain").val()]);
})

At Webpart B I added a Eventlistener :

parent.$("document").on('datachange',function (event, data) {
    $("#dataout").html(data);
});

When I change something at WebpartA , the event is triggered , but it never reaches the event listener at WebpartB. Is there something wrong with my code or is it just impossible to communicate between the two iframes with custom Events ?

Thank you for your help.

解决方案

fixxed the problem by changeing "document" to "body" so Webpart A is :

$("#datain").change(function () {
    parent.$("body").trigger("datachange", [$("#datain").val()]);
})

and Webpart B is :

parent.$("body").on('datachange',function (event, data) {
    $("#dataout").html(data);
});

这篇关于从iframe触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆