trigger Event from iframe

可紊 提交于 2020-01-04 05:44:07

问题


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.


回答1:


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);
});


来源:https://stackoverflow.com/questions/41137943/trigger-event-from-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!