Home >Web Front-end >JS Tutorial >iframe adaptive height js script compatible with mainstream browsers_javascript skills

iframe adaptive height js script compatible with mainstream browsers_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:04:321098browse

Compatible with the Iframe adaptive height of mainstream browsers, the js script is as follows:

Copy code The code is as follows:

//iframe height adaptive
function iframeAutoFit(iframeObj) {
setTimeout(function () {
if (!iframeObj) return;
iframeObj.height = (iframeObj.Document ? iframeObj. Document.body.scrollHeight : iframeObj.contentDocument.body.offsetHeight);
}, 200);
} < /span>

Call method:
Copy code The code is as follows:



Extension:
Copy the code The code is as follows:

//Dynamicly add styles
function addSheetFile(obj, path) {
if (obj == undefined || obj == null)
obj = document;

var fileref = obj.createElement("link")
fileref.rel = "stylesheet";
fileref.type = "text/ css";
fileref.href = path;
fileref.media = "screen";
var headobj = obj.getElementsByTagName('head')[0];
headobj.appendChild(fileref) ;
}
Statement:
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