Jsp page iframe highly adaptive js Code, iframejs

Source: Internet
Author: User

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>
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.