IFrame Adaptive width, height IE6 7 8,firefox 3.86 test pass _javascript Tips

Source: Internet
Author: User
Nonsense not to say, put on code, also be a code store of their own.
Copy Code code as follows:

var temp_iframe
var content = document.getElementById (' right '); In a DOM container with ID right, create IFRAME and wide-high adaptive
var c = 0;
function append (filename)
{
var the_iframe = "HelpFile" + C;
Temp_iframe = document.createelement ("iframe");
TEMP_IFRAME.SRC = filename;
temp_iframe.scrolling = "No";
Temp_iframe.setattribute ("frameborder", "0");
Temp_iframe.id = The_iframe;
Temp_iframe.name = The_iframe;
Scroll (0, 0);
content.innerhtml = "";
Content.appendchild (Temp_iframe);
if (document.all)
{
Temp_iframe.attachevent (' onload ', function ()
{
Temp_iframe.setattribute ("width", window.frames[the_iframe].document.body.scrollwidth); Adaptive width
Temp_iframe.setattribute ("height", window.frames[the_iframe].document.body.scrollheight); Self-adaptive high
});
}
Else
{
Temp_iframe.addeventlistener (' Load ', function ()
{
Temp_iframe.setattribute ("width", window.frames[the_iframe].document.body.scrollwidth);
Temp_iframe.setattribute ("height", window.frames[the_iframe].document.body.scrollheight);
}, False);
}
C + +;
return false;
}
/* Call method
Save this script as a script file: Iframe.js, and then call in the foreground page:
------------------------------------------------------------------------
<a href= "index.html" onclick= "return append (' xxxx.html ')" class= "Li1" >
<div id= "right" ></div>
<script type= "Text/javascript" src= "Iframe.js" ></script>
------------------------------------------------------------------------
Or remove the last return false in the script, front desk:
------------------------------------------------------------------------
<a href= "javascript:append (' favorite/favorites.html ')" class= "Li1" >
<div id= "right" ></div>
<script type= "Text/javascript" src= "Iframe.js" ></script>
------------------------------------------------------------------------
*/

Hey, in which, the last set of adaptive wide-height, can actually be proposed to become a function to call.
This I did not go to do so, have to see the article friend, can be encapsulated.

Among them, there are some inconvenient, for example, every time I set up the IFRAME must be different name and ID, delete the original has not been created ...
I hope we can teach you a lot.

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.