向页面添加多个iframe时高度自适应

后台代码如下:

/**
 * 办理足迹登记、移送、交办、确认、退回统一详情页
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
 @RequestMapping(value = "commonGet")
 public ModelAndView commonGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
     ModelAndView mv = this.getAutoView();
	Long caseId = RequestUtil.getLong(request, "caseId");
	String caseType = RequestUtil.getString(request, "caseType");
	String stepType = RequestUtil.getString(request, "stepType");
	Map map = new HashMap();
	if("2".equals(caseType)){
		List<ClueCaseinfo> clueCaseinfoList = clueCaseinfoService.getByClueId(caseId);
		for (int i = 0; i < clueCaseinfoList.size(); i++) {
			CaseJudge caseJudge = caseJudgeService.getByCaseIdAndCaseType(Long.valueOf(clueCaseinfoList.get(i).getCaseId()), String.valueOf(clueCaseinfoList.get(i).getCaseType()));
			OurClueHistory ourClueHistory = ourClueHistoryService.getByClueIdAndStepType(caseJudge.getJudgeId(),stepType);
			if(ourClueHistory != null){
				map.put(ourClueHistory.getId(),caseJudge);
			}
		}
	}else{
		CaseJudge caseJudge = caseJudgeService.getByCaseIdAndCaseType(Long.valueOf(caseId), String.valueOf(caseType));
		OurClueHistory ourClueHistory = ourClueHistoryService.getByClueIdAndStepType(caseJudge.getJudgeId(),stepType);
		if(ourClueHistory != null){
			map.put(ourClueHistory.getId(),caseJudge);
		}
	}
	return mv.addObject("map", map);
}

前台代码如下(红色为主要代码):

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>办理足迹登记、移送、交办、确认、退回共用详情</title>
<%@include file="/commons/include/newGet.jsp"%>
<script type="text/javascript">
	
	$(function(){
		<c:forEach items="${map}" var="m">
			judgeClueDetail(${m.key},${m.value.caseId},${m.value.caseType})
		</c:forEach>
	})
	
	function setIframeHeight(iframe) {
		if (iframe) {
			var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
			if (iframeWin.document.body) {
				iframe.height = (iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight)+15;
			}
		}
	}

	//详情
      function judgeClueDetail(ourClueHistoryId,caseId,caseType){
          var _url = "${ctx}/pwlp/judge/caseJudge/get.ht?clueHistoryId="+ourClueHistoryId+"&caseId="+caseId+"&caseType="+caseType+"&timeLineFlag=yes";
      	  //添加iframe标签
          var body = document.getElementsByTagName("body");
          var div = document.createElement("div");
          div.innerHTML = "<iframe src='"+_url+"' frameborder='0' scrolling='no' style='100%; padding-bottom:0px' onload='setIframeHeight(this)'></iframe>";
          document.body.appendChild(div);
      }
</script>
</head>
<body style="background: #f4f4f4">
	
</body>

  

原文地址:https://www.cnblogs.com/henuyuxiang/p/12806934.html