Jsp page iframe highly adaptive js Code, iframejs
The following operations are written in the body, outside the form
<Iframe id = "agentFrame" name = "agentFrame" src = "" width = "0" height = "0" style = "display: none; "> </iframe> <script type =" text/javascript "> function sethash () {hashH = document.doc umentElement. scrollHeight; // obtain its own height urlC = "/test. jsp "; // set the src document of iframeA. getElementById ("agentFrame "). src = urlC + "#" + hashH; // pass the height as a parameter} window. onload = sethash; </script>
Test. jsp is as follows:
<%@ 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>
How does the jsp iframe automatically change according to the size of the imported page?
Use a JS to automatically increase the frame height. You can <iframe id = "myframe" name = "myframe" width = "100%" src = "TheFirst. aspx "scrolling =" no "frameborder =" 0 "onload =" this. height = 100 ">
</Iframe> <script type = "text/javascript">
Function reinitIframe ()
{
Var iframe = document. getElementById ("myframe ");
Try {
Var bHeight = iframe.content20.doc ument. body. scrollHeight;
Var dHeight = iframe.content?document.doc umentElement. scrollHeight;
Var height = Math. max (bHeight, dHeight );
Iframe. height = height;
} Catch (ex ){}
}
Window. setInterval ("reinitIframe ()", 200 );
</Script>
JS cross-origin control iframe, enabling iframe to adapt to the complete code
Parent page: stockPoolHistoryView. jsp
<Head>
<Script type = "text/javascript">
Function iframeStockPoolHistoryViewRecPoolGoGoGo (width, height ){
Var appSubIframeObj = document. getElementById ("stockPoolHistoryViewRecPool ");
AppSubIframeObj. style. height = height + "px ";
}
</Script>
</Head>
<Body>
<Table>
<Tr>
<Td>
<Iframe id = "stockPoolHistoryViewRecPool"> </iframe>
</Td>
</Tr>
</Table>
</Body>
Subpage: stockPoolHistoryViewRecRool. jsp
<Head>
<Script type = "text/javascript">
Function iframeHeightWidth (){
Var height = document. body. scrollHeight;
Var width = document. body. scrollWidth;
Window. parent. iframestockpoolhistoryviewrecpoolgogo (width, height );
}
</Script>
</Head>
<Body>
<Fs: form>
</Fs: form>
<Script type = "text/javascript">
IframeHeightWidth ();
</Script>
</Body>