iframe的高度自适应
<script> function SetWinHeight(obj) { var win = obj; if (document.getElementById) { if (win && !window.opera) { if (win.contentDocument&& win.contentDocument.body.offsetHeight) win.height = win.contentDocument.body.offsetHeight; else if (win.Document && win.Document.body.scrollHeight) win.height = win.Document.body.scrollHeight; } } } </script>
上面是iframe高度自适应的js代码,把它插入到自己写的iframe标签的onload=" "属性中即可(推荐js写到<head>标签内部)。
html如下:
<div> <iframe src="http://192.168.3.91:8080/cobo/portal/comment.ptview" scrolling="no" frameborder="0" width="100%" height="100%" onload="Javascript:SetWinHeight(this)"> </iframe> </div>
<!-- 顺带写上jsp动态include引入页面和传参的方式 -->
<jsp:include page="showCommentPortal.jsp">
<jsp:param name="infoLinkId" value="<%=infoLink.getInfoLinkId()%>" />
<jsp:param name="infoSortId" value="<%=infoSort.getInfoSortId()%>" />
</jsp:include>