怎样才能在整个网页所有的js(包括广告js)都加载完了。什么图片什么都弹出来了。才最后执行我想要的js呢?
我试过
window.onload结果不行
也试过onreadychange也还是不行
 

解决方案 »

  1.   

    window.onload怎么可能不行?那你把广告啊之类的js放在什么地方了?
    实在不行,把你要执行的js放到<body>标签刚好结束前
      

  2.   

    真的是不行,那些广告js好像还要在外面调用图片什么的,他发送请求是在onload之前的,但是图片要弹出来了呢,就必须会等到我那个onload结束之后才会弹出没办法了。
      

  3.   

    那你通过判断图像是否加载完成然后再载入你的js就好了啊
    image有个叫.load的方法,你上网查查
      

  4.   

    用firefox,看它的代码是这样子的:<script>联盟的广告js</script>
    <script>window.onload的我的js</script>
    <div>
    <embed>联盟的广告窗口
    </div>
    无论我怎么设置我的js,他的广告div总是在最后的。我就不明白了。
      

  5.   

    <script>联盟的广告js</script>
    <div>
    <embed>联盟的广告窗口
    </div>
    <script>我的js</script>
    这样试试、、
      

  6.   

    可不可能是它的脚本的功能是在页面内容之外另外加进一个div图层呢??获取body的value,然后在value后面+<div>广告</div>,然后再输出
      

  7.   

    如果可以这样,我早这样了。关键是,无论我怎么动,顺序就是不变,他的<div>永远在最后
      

  8.   

    目的是想在 广告的js  执行之后 再去家在  某些js  那你就在加载广告的js 执行完成之后调用呗 不用再onload  或者onreadychange 事件里面添加所有的都加在完毕 ..   那你要不加个 事件段   过1秒或者2面   啥的 在执行这段js  
      

  9.   

    我看过这段代码了。也贴出来让大家帮忙看看:var $dom={
    ts : 0,
    adUrl : yP_statsUrl,
    adw : yP_width,
    adh : yP_height,
    Ie :(navigator.appName == "Microsoft Internet Explorer"),
    g : function(){
    var d = document.body;e=document.documentElement;
    if(document.compatMode=="BackCompat"){
    this.w=d.clientWidth;
    this.h=d.clientHeight;
    this.l=d.scrollLeft;
    this.t=d.scrollTop;
    }else {
    this.w=e.clientWidth;
    this.h=e.clientHeight;
    this.l=e.scrollLeft==0?d.scrollLeft:e.scrollLeft;
    this.t=e.scrollTop==0?d.scrollTop:e.scrollTop;
    };
    },
    c : function (){
    var yP_fileext=yP_imgurl.substr(yP_imgurl.lastIndexOf(".")).toLowerCase();
    var doc=document;
    this.popup = doc.createElement("div");
    s = this.popup.style;
    s.overflow = "hidden";
    s.position = "absolute";
    s.zIndex = 1000000;
    s.width = this.adw+"px";
    s.height = this.adh+"px";
    s.border= 0;
    s.textAlign='left';
    if(yP_fileext!='.swf'){
    if(yP_planType=='cpv') {
    this.stra = "<a target='_blank' href="+yP_tourl+" onclick='$dom.uc()'><img src='"+yP_imgurl+"' border='0' width='"+(this.adw)+"' height='"+(this.adh)+"'></a>";
    }else{
    this.stra = "<a target='_blank' href="+this.adUrl+" onclick='_zh_(event)' onmouseover='_zv_();_zn_(event);_zt_(event)' onmousedown='_zc_(event)' onmouseup='_zc_(event)'><img src='"+yP_imgurl+"' border='0' width='"+(this.adw)+"' height='"+(this.adh)+"'></a>";
    }
    yP_C_zy_str=this.stra;
    }else {
    if(yP_planType=='cpv') {
    this.stra = "<a target='_blank' href="+yP_tourl+" onclick='$dom.uc()'>";
    }else{
    this.stra = "<a target='_blank' href="+this.adUrl+" onclick='_zh_(event)' onmouseover='_zv_();_zn_(event);_zt_(event)' onmousedown='_zc_(event)' onmouseup='_zc_(event)'>";
    }
    dL_flash = this.F("pf_123",yP_imgurl, this.adw, this.adh);
    yP_C_zy_str=this.stra+"<div style='cursor:pointer;z-index:100000;position:absolute;height:"+this.adh+"px;width:"+this.adw+"px;background-color:#fff;opacity:0.01;filter:alpha(opacity:1);'></div></a><div style=' z-index:9999;cursor:pointer;text-align:center' >"+dL_flash+"</div>";
    }
    this.popup.innerHTML='<img src="'+yP_imgServer+'/images/close.gif" style="position:absolute;top:2px;right:2px;cursor:pointer;width;15px;height:15px;z-index:110000" onclick="$dom.hi()">'+yP_C_zy_str+'';
    s.display="none";
    if(this.Ie) {document.body.insertBefore(this.popup) ;} else {document.body.appendChild(this.popup);}
    },
    hi : function(){
    clearInterval($dom.sI);
    document.body.removeChild(this.popup);
    },
    s : function (){
    clearInterval($dom.zy);
    setTimeout(function(){$dom.r();},50);
    },
    r: function (){
    $dom.c();
    $dom.sI=setInterval(function(){$dom.m();},10);
    },
    m: function (){
    $dom.g();
    this.popup.style.left=(this.w-this.adw+this.l)+"px";
    this.popup.style.top=(this.h-this.ts+this.t-3)+"px";
    this.popup.style.display="";
    if(this.ts<this.adh){
    this.ts+=7;
    if(this.ts>this.adh){
    this.ts=this.adh;
    if(this.ts-10>this.adh) clearInterval($dom.sI);
    };
    };
    },
    uc :function(){
    a=new Image();
    a.src=yp_doclick2url;
    },
    t: function (){
    if(window.attachEvent){
    window.attachEvent("onload",function (){$dom.s();
    });
    }else {
    window.addEventListener("load",function (){
    $dom.s();
    },true);
    }
    if(yP_planType=='cpv'){
    setTimeout(function(){$dom.Va();},1000);
    }
    },
    Va: function (){
    if(document.body){
    zY_a=new Image();
    zY_a.src=yP_statsUrl;
    }
    },
    F : function(idad, swfurl, ws, hs)
    {
    var str = '<embed src="'+swfurl+'" type="application/x-shockwave-flash" height="'+hs+'" width="'+ws+'" id="'+idad+'" name="ZyadsFlashAd" quality="high" wmode="transparent" allownetworking="none" allowscriptaccess="always" >';
    return str;
    }
    };
    $dom.t();
      

  10.   

    应该主要因为这段代码又用了onload侦听,又用了createElement+appendChild/insertBefore这些方法来强逼一定是最后加载广告。。而且他的style写得乱七八糟。真是难搞
      

  11.   

    兄弟,script标签有个属性——defer,<script defer="defer">...</script>,那么这段js脚本就会等到文档加载完毕才会执行。
      

  12.   

    你用一个setInterval  函数监听图片以及其他js的加载状态,加载完成后,将状态设置为true,然后在setInterval 里面的function(也就是你的js代码) 就会被执行,这里你就加个状态判断就可以了。最后吧计时器清掉就ok了。很简单的。还不懂的话,我写个Demo给你。