function context(id) {
$("#t_context").html("");
var html=" <iframe id='t_contextPage' MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no src=\""+id+".html\" width=\"100%\" height=\"100%\">\n" +
" </iframe>";
$("#t_context").html(html);
//解决打开高度太高的页面后再打开高度较小页面滚动条不收缩
changeHeight();
}
function changeHeight() {
var ifr = document.getElementById('t_contextPage');
ifr.style.height='0px';
var iDoc = ifr.contentDocument || ifr.document;
var height = calcPageHeight(iDoc);
if(height < 550){
height = 600;
}
ifr.style.height = height + 'px';
}
// 计算页面的实际高度,iframe自适应会用到
function calcPageHeight(doc) {
var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight);
var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight);
var height = Math.max(cHeight, sHeight);
return height
}
由于内嵌页面是个bootstrap 的table 这里就会有改变页码大小的事件,子页面改变页面大小,父类并没有感知到,所以我们需要在table加载完数据之后去触发父类changeHeight()的方法,去改变父类页面的高度,这样才会完整的显示出数据列表,不会被隐藏。
onLoadSuccess:function () {
//数据加载完成之后,触发父类的改变页面高度的方法,确保页的大小发生变化之后导致还是原先的高度,
parent.changeHeight();
}
这样就完整解决了内嵌页面高度的问题
子页面改变父页面的title
parent.document.title=document.title;