1, mzone.cc.js file, to create a namespace-based object
The code is as follows |
Copy Code |
function Mzone () {}; /**
* Desc: Object creation using the given object path * Para:objpath-Object path, String type, format: Xx.yy.zz * Return: No value returned, use object path directly when creating success */ Mzone.createobject = function (/*string*/objpath) {
if (!objpath | | typeof (Objpath)!= ' string ') return; var root = window; var parts = objpath.split ('. '); for (var i = 0; i < parts.length i + +) { if (typeof (Root[parts[i]]) = = ' undefined ') root[parts[i]] = {}; root = Root[parts[i]]; } }; |
2, Mzone.cc.iframe.js file, the automatic height of the iframe adjustment
* Title:iframe Height automatic adjustment, adapt to each browser (IE, Firefox, chrome, etc.). Note that you must test in the Web container when testing in chrome
The code is as follows |
Copy Code |
Mzone.createobject ("Mzone.cc.iframe"); /** * Desc: Define object Mzone.cc.iframe static method to realize dynamic adjustment of IFRAME * Para:iframe-The IFrame object to adjust, Dom object * Extheight-Automatically calculate the height of the iframe after an additional height value, digital * Minimum height of minheight-iframe, digital type * Return: No value returned */ Mzone.cc.iframe.autoHeight = function (/*object*/iframe,/*int*/extheight,/*int*/minheight) { Iframe.style.display = "block"; if (iframe.contentdocument && iframe.contentDocument.body.offsetHeight) {//Ff,chrome etc var h = parseint (iframe.contentDocument.body.offsetHeight) + 50; H + + extheight; if (H < minheight) H = minheight; Iframe.height = h + "px"; else if (IFRAME. Document && iframe. Document.body.scrollHeight) {//IE var h = parseint (iframe). Document.body.scrollHeight) + 35; H + + extheight; if (H < minheight) H = minheight; Iframe.height = h + "px"; } else { var h = parseint (iframe.contentWindow.document.documentElement.scrollHeight) + 35; H + + extheight; if (H < minheight) H = minheight; Iframe.height = h + "px"; } } |
The above two JS is saved and introduced to the page can be called as follows to achieve the height of the iframe automatic adjustment:
The code is as follows |
Copy Code |
var iframe = document.getElementById ("Iframe_body"); IFrame Object
var extheight = 0; The height value of the IFRAME to be added var minheight = 300; Minimum height setting for IFRAME Mzone.cc.iframe.autoHeight (IFRAME, Extheight, minheight);
|
The above scripts are tested in IE, Firefox, and Chrome, and you need to be aware that the offline test in Google's Chrome browser is faulty and needs to be tested in a Web container such as Apache or IIS to see the effect.