Home > Web Front-end > JS Tutorial > iframe adaptive width, height ie6 7 8, firefox 3.86 test passed_javascript skills

iframe adaptive width, height ie6 7 8, firefox 3.86 test passed_javascript skills

WBOY
Release: 2016-05-16 18:22:21
Original
1506 people have browsed it

Without further ado, pasting the code can be regarded as your own code storage.

Copy code The code is as follows:

var temp_iframe
var content = document.getElementById( 'right'); //In the DOM container with the id of right, create iframe and adapt width and height
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); //Adaptive height
});
}
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 it on the front page:
------------ -------------------------------------------------- ----------



--------- -------------------------------------------------- -------------
Or remove the last return false in the script, frontend:
----------------------------- -------------------------------------------------- --



--------------------- -------------------------------------------------- -
*/

Hey, the final setting of adaptive width and height can actually be made into a function to call.
I didn’t do that. Friends who have seen the article can package it themselves.

Among them, there are still some inconveniences. For example, the iframe I create must have a different name and ID every time, and it is not possible to delete the original one immediately...
I still hope you can give me some advice.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template