时间:2022-12-26加入收藏
/**
* 待iframe载入后执行函数
*
* @param {Element} el
* @param {Function} func
*/
var onIframeLoad = function(el, func) {
var cb = function() {
try {
func.call(this);
} catch (e) {}
}
if (TB.bom.isIE) {
el.onreadystatechange = function(){
if (el.readyState == 'complete') {
setTimeout(cb, 0);
el.onreadystatechange = null;
}
}
} else {
el.onload = function() {
setTimeout(cb, 0);
el.onload = null;
}
}
};
/**
* 跨域iframe高度自适应封装
*
* @param {String} name
*/
var crossDomainIframe = function(name) {
var iframe = YAHOO.util.Dom.get(name);
var xclient = 'xclient';
onIframeLoad(iframe, function(){
try {
var h = frames[name].frames[xclient].location.hash.substring(1);
if (h == '') {
var func = arguments.callee;
setTimeout(function(){ func(); }, 20);
return;
}
iframe.style.height = h+'px';
} catch (e) {}
});
};
// 执行
crossDomainIframe('frame_content');
(function(){
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
function adjust() {
var h = document.documentElement.scrollHeight || document.body.scrollHeight;
try {
if (document.getElementById('xclient')) {
var divEl = document.getElementById('xclient').parentNode;
console.log(document.getElementById('xclient').parentNode);
divEl.parentNode.removeChild(divEl);
}
var el = document.createElement('div');
el.innerhtml = '';
document.body.appendChild(el);
} catch(e) {}
}
addLoadEvent(adjust);
})();