一.带有iframe的父页
1)html
<!DOCTYPE html>
<html>
<head>
<title>带有iframe的父页</title>
</head>
<body>
<iframe src="" id="businessPage" width="99%" height="150px;" style="margin:5px;" onclick="alert('aaa');"></iframe>
</body>
</html>
2)js
$(document).ready(function(){
$("#businessPage").load(function(){//用于每次刷新时控制iframe高度初始化
//$(this).height(0);
var iframeHeight;
if($(this)[0].contentWindow.getApproveBusinessPageHeight){
iframeHeight = $(this)[0].contentWindow.getApproveBusinessPageHeight();
}else{
iframeHeight = $(this).contents().height() + 40;
}
$(this).height( iframeHeight < 150 ? 150 : iframeHeight );
});
$("#businessPage").attr("src", "${business.pageUrl }");
});
二.iframe加载的子页
1)js
/*自定义iframe 高度的方法*/
function getApproveBusinessPageHeight(){
return $("#comMenuFrame").height() + 40;
}