//slotId: 百度广告id//width: 宽度//mtop: 上边距,纯数字//mbottom: 下边距,纯数字function BaiduAdFunc(slotId,width,mtop,mbottom) { mtop = mtop ? mtop : 0; mbottom = mbottom ? mbottom : 0; if(width.toString().indexOf('%')==-1 && width.toString().indexOf('px')==-1) width = width+'px'; document.write('<iframe id="BaiduAdFrame_'+slotId+'" name="BaiduAdFrame_'+slotId+'" height="0" width="'+width+'" scrolling="no" allowtransparency="true" src="/baiduad/proxy.html?id='+slotId+'" frameborder="0" style="border:0px"></iframe>'); var iframe = document.getElementById("BaiduAdFrame_"+slotId); if(iframe.attachEvent){ //alert('a'); iframe.attachEvent("onload", function(){ try{ var temp_id = "baidu_clb_slot_iframe_"+slotId; if(!iframe.contentWindow.document.getElementById(temp_id)){ temp_id = temp_id+"_0"; if(!iframe.contentWindow.document.getElementById(temp_id)){ return; } } var content = iframe.contentWindow.document.getElementById(temp_id).contentWindow.document.body.innerHTML; if(content){ var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight); iframe.height = height; if(window.opera){ iframe.setAttribute('style','border:0px;margin-top:'+mtop+'px;margin-bottom:'+mbottom+'px;'); } else { iframe.style.marginTop = mtop; iframe.style.marginBottom = mbottom; } } } catch (ex){} }); } else { //alert('b'); iframe.onload = function(){ try{ var temp_id = "baidu_clb_slot_iframe_"+slotId; if(!iframe.contentWindow.document.getElementById(temp_id)){ temp_id = temp_id+"_0"; if(!iframe.contentWindow.document.getElementById(temp_id)){ return; } } var content = iframe.contentWindow.document.getElementById(temp_id).contentWindow.document.body.innerHTML; if(content){ var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight); iframe.height = height; iframe.setAttribute('style','border:0px;margin-top:'+mtop+'px;margin-bottom:'+mbottom+'px;'); } } catch (ex){} } }}
|
|
|
|
评论
直达楼层