zoukankan      html  css  js  c++  java
  • iframe跨域-Js通信的一种方式

    向外通知:

    iframe外监听:
    window.addEventListener('message',function(e){
            var data = e.data;
            console.log(data.info);//some info
            console.log(data.action);//dosomething
            
            var height = data.height;
            if(height < 250){
                height = 250;
            }
            var ifr = document.getElementById('iframeName').style.height = height + 'px';     
        });
    iframe内发消息:
    window.parent.postMessage({height:$(document).height()}, '*');
    window.parent.postMessage({action: 'dosomething', info: 'some info'},"*");
    

     

    向内通知:

    iframe内监听:
    window.addEventListener("message", function(e){
        var data = e.data;
        console.log(data.info);//some info
        console.log(data.action);//dosomething   
    });
    iframe外发消息:
    document.getElementById('iframeName').contentWindow.postMessage({action: 'dosomething', info: 'some info'},"*");
    

      

  • 相关阅读:
    Evensgn 的债务
    Passward
    拯救莫莉斯
    文艺平衡树
    Fliptile 翻格子游戏
    Making the Grade (bzoj1592)
    紧急疏散evacuate
    Password
    [NOIP2015]斗地主
    运输问题1
  • 原文地址:https://www.cnblogs.com/songjianming/p/13854523.html
Copyright © 2011-2022 走看看