postMessage Source IFrame

前端 未结 6 1921
执念已碎
执念已碎 2020-12-13 15:21

I\'m working on a website with cross-domain iframes that are resized to the correct height using postMessage. The only problem I\'m having is identifying which iframe has wh

6条回答
  •  醉酒成梦
    2020-12-13 15:53

    I have found the solution from here: How to share a data between a window and a frame in JavaScript

    Parent:

    var frames = document.getElementsByTagName('iframe');
    for (var i = 0; i < frames.length; i++) {
        if (frames[i].contentWindow === event.source) {
            $(frames[i]).height(event.data); //the height sent from iframe
            break;
        }
    }
    

提交回复
热议问题