Issue communication with postMessage from parent to child iFrame

前端 未结 2 958
青春惊慌失措
青春惊慌失措 2021-01-12 21:36

I\'m having an issue communicating from my parent window to the child iFrame. But in the other side, everything works perfectly. Here is how I get the chil iFrame object in

相关标签:
2条回答
  • 2021-01-12 22:05

    Below code also works.

    $('#id')[0].contentWindow.postMessage("hello world",targetOrigin);

    There is a difference between jQuery selector and document.getElementById.

    Document.getElementByID returns HTML DOM object.
    jQuery selector returns jQuery object.

    For more information please find below link. document.getElementById vs jQuery $()

    0 讨论(0)
  • 2021-01-12 22:08

    try this

    var iFrame = document.getElementById('Frame');
    iFrame.contentWindow.postMessage("message", "http://contoso.com");
    

    I had this problem too. I found solution from this website https://www.viget.com/articles/using-javascript-postmessage-to-talk-to-iframes

    0 讨论(0)
提交回复
热议问题