iframe父子页面通讯解决方案
有两点要注意
onload加载完成再进行操作
子页面延时获取
场景是这样的,父级页面嵌套了多个iframe,report_six.html子级页面按需加载数量,且每个子页面渲染不同的数据。
父页面for循环加载子页面数量,动态生成id,根据对应的id,传值给对应的子级页面元素,一定要写在onload里面
下面是父页面
<body>
<iframe src="report_one.html" frameborder="0" width="630" height="891"></iframe>
<iframe src="report_two.html" frameborder="0" width="630" height="891"></iframe>
<iframe src="report_three.html" frameborder="0" width="630" height="891"></iframe>
<iframe src="report_four.html" frameborder="0" width="630" height="891"></iframe>
<iframe src="report_five.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_0" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_1" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_2" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_3" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_4" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="report_ten" src="report_ten.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="report_eleven" src="report_eleven.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="report_nine" src="report_nine.html" frameborder="0" width="630" height="891"></iframe>
</body>
<script src="./js/jquery-2.1.4.js"></script>
<script>
if(obj.type == 3){
$('<iframe src="report_one.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
$('<iframe src="report_two.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
$('<iframe src="report_three.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
$('<iframe src="report_four.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
$('<iframe src="report_five.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
var rank_a = obj.k.length;
for(var i = 0;i < rank_a;i++){
$('<iframe id="a_' + i + '" src="report_six.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
}
$('<iframe id="report_ten" src="report_ten.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
$('<iframe id="report_eleven" src="report_eleven.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
var cancer = obj.c.length;
if(cancer > 0){
$('<iframe id="report_nine" src="report_nine.html" frameborder="0" width="630" height="891"></iframe>').appendTo('body');
}
window.onload = function(){
var rank_a = obj.m07.dis_risk.length;
for(var i = 0;i < rank_a;i++){
$('#a_' + i).contents().find('#rank').val(i);
}
$('#report_ten').contents().find('#change').html('四');
$('#report_eleven').contents().find('#change').html('五');
$('#report_nine').contents().find('#change').html('六');
}
}
</script>
子级页面带有默认值的元素input#rank接收数据,为了确定接收到参数,设置一个定时器,不等于默认值的情况下就表示接收成功,接收成功之后清除定时器执行业务代码
下面是子页面
<body>
<section>
<div id="mainChart" class="chart"></div>
</section>
<input type="hidden" id="rank" value="a"/>
<script src="./js/echarts-all-3.js"></script>
<script>
var timer = setInterval(function(){
var rank_value = document.getElementById("rank").value;
if(rank_value != 'a'){
clearInterval(timer);
//执行代码
}
},2000);
</script>
</body>
关注公众号
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
HTML转pdf
<body> <div class="chart" id="chart"> <img src="../images/group10.png" alt="图片加载失败" /> <img src="../images/permission.png" alt="图片加载失败" /> Hello </div> <span id="screenImage" class="btn-screen" >截屏</span> <a id="downImage" href="" class="btn-screen" >下载</a> <img id="screenShotImg" src="../images/favicon.jpg" alt="图片" class="screen" /> </body> <script src="../js/jquery-2.1.4.js"></script> <script src="../plug/canvas/...
-
下一篇
Echarts极地坐标图直径半径设置
var dom = document.getElementById("theChart"); var myChart = echarts.init(dom); option = null; var param_a = [13652,16154,18615,20733,16578,13036,14167,15047,15573,15854]; var param_c = [12652,15154,17615,19733,15678,12036,15167,16047,15573,16854]; var res_data = []; for(var t = 0;t < param_a.length;t++){ if(param_c == ''){ res_data.push([0,param_a[t],param_a[t]]); }else{ res_data.push([0,param_c[t],param_a[t]]); } } var data = res_data; /*var data = [ [2000, 10000, 10385.71], [2000, 10000, 1...
相关文章
文章评论
共有0条评论来说两句吧...

微信收款码
支付宝收款码