/** * Cross-domain IFRAME Adaptive height solution * Author:changyin@taobao.com * Copyright (c), Taobao Inc. All rights reserved. */ var Loader = new function () { var doc = Document,body = Doc.body, Self = this, Get the parameters in the URL Getrequest = function (name) { var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)", "I"), r = Window.location.search.substr (1). Match (REG); Return (r!=null)? Unescape (r[2]): null; }, Get configuration, script priority is greater than parameters in URL GetConfig = function () { var scripts = doc.getelementsbytagname (' script '), script = Scripts[scripts.length-1]; return function (param) { var p = script.getattribute (param); Return p? P:getrequest (param); }; }(), Agent Height Proxyheight = 0, ID of the top page frame Frameid = GetConfig ("Data-frameid"), Monitor real-time update height interval Timer = GetConfig ("Data-timer"), Get the URL of the agent Getproxyuurl = GetConfig ("Data-proxy"), Create an IFRAME for the agent Proxyframe = function () { var el = doc.createelement ("iframe"); El.style.display = "None"; El.name= "proxy"; Return el; }(); Reset Height This.resize = function () { Proxyheight = Body.offsetheight; PROXYFRAME.SRC = Getproxyuurl + "? data-frameid=" + frameid+ "&data-frameheight=" + (PROXYHEIGHT+40); } This.init = function () { var init = function () { Body.appendchild (Proxyframe); Self.resize (); Whether update if (!isnan (timer)) { Timer = timer<500?500:timer; Window.setinterval (function () { if (body.offsetheight!= proxyheight) { Self.resize (); } },timer); }; }; if (Doc.addeventlistener) { Window.addeventlistener ("Load", init,false); }else{ Window.attachevent ("onload", init); } If the JS framework is introduced, it is recommended to change the above sentence for example: Kissy.ready (function () {init ();}); } }; Loader.init (); |