以下操作寫在body裡面,form表單外
1 2 3 4 5 6 7 8 9 <iframe id="agentFrame" name="agentFrame" src="" width="0" height="0" style="display:none;" ></iframe> <script type="text/javascript"> function sethash(){ hashH = document.documentElement.scrollHeight; //獲取自身高度 urlC = "/test.jsp"; //設置iframeA的src document.getElementById("agentFrame").src=urlC+"#"+hashH; //將高度作為參數傳遞 } window.onload=sethash; </script>test.jsp如下:
1 2 3 4 5 6 7 8 9 <%@ page contentType="text/html;charset=GBK" language="java"%> <script> function pseth() { var iObj = parent.parent.document.getElementById('infoFrame'); iObjH = parent.parent.frames["infoFrame"].frames["agentFrame"].location.hash; iObj.style.height = iObjH.split("#")[1]+"px"; } window.onload=pseth(); </script>