在IE8中不工作window.onload [英] Does not work window.onload in IE8

查看:114
本文介绍了在IE8中不工作window.onload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的图像切换器,用于手动图像切换器和传送带。在IE 8中,它很奇怪。在轮播场景中,图像只切换一次,然后死亡。但是(!)当我实现Firebug Lite并试图追踪 - 它运行良好,只有在上使用了萤火虫...我尝试了一些技巧,我发现,但这完全没有目的。我不知道是什么导致了这种行为。如何解决它?



js

 函数toSlide(wrapper,选项){
var active = $('#'+ wrapper +'div.active');
var slide;
var direction;

if(active.length === 0){
active = $('#'+ wrapper +'div:last');
}

if(options === null){
options = {};
options.reverse = false;
options.animate = false;
} else {
options.reverse = options.reverse === null? false:options.reverse;
options.animate = options.animate === null? false:options.animate;
}

direction = options.reverse === true? active.prev():active.next();

slide = direction.length?方向:$('#'+ wrapper +'div:first');

if(options.animate === true){
active.addClass('last-active');

slide.addClass('active')
.css({opacity:0.0})
.animate({opacity:1.0},1000,function(){
active.removeClass('active last-active');
});
} else {
slide.addClass('active');
active.removeClass('active');



函数startSlideShow(){
setInterval(function(){toSlide('slideshow',{'animate':true});}, 5000);
};

window.onload = function(){
if(document.location.pathname =='/'){startSlideShow();};
};

html头像

 <! -  [if IE 8]> 
< link rel =stylesheethref ={{MEDIA_URL}} css / ie8.csstype =text / cssmedia =screen,projection/> < html lang =enclass =no-js ie8>
< script defer src =ie_onload.js>< / script>
< script>!window.jQuery&& document.write(unescape('%3Cscript src ={{MEDIA_URL}} js / jquery-1.6.2.js%3E%3C / script%3E'))< / script>
< script type =text / javascriptsrc =http://fbug.googlecode.com/svn/lite/branches/firebug1.3/content/firebug-lite-dev.js><<< ; /脚本>
<![endif] - >

位于html底部

 <! - 抓取Google CDN的jQuery。必要时回落到当地 - > 
< script type =text / javascriptsrc =https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js>< / script>
<! - < script>!window.jQuery&& document.write(unescape('%3Cscript src ={{MEDIA_URL}} js / jquery-1.4.2.js%3E%3C / script%3E'))< / script> - >

<! - 脚本通过ant构建脚本串联和缩小 - >
< script src ={{MEDIA_URL}} js / plugins.js>< / script>
< script src ={{MEDIA_URL}} js / script.js>< / script>
<! - - 结尾级联和缩小脚本 - >


解决方案

原因是IE8中的非函数window.onload 。我做了正确的伎俩,但犯了一个愚蠢的错误。所以我解决了这个问题:



 <! -  -  [如果IE 8]> 
< script defer src =ie_onload.js>< / script>
<![endif] - >

现在是

 <! -  [if IE 8]> 
< script defer src ={{MEDIA_URL}} js / ie_onload.js>< / script>
<![endif] - >

in ie_onload.js

  document.body.onload = function(){
imageViewer();
//和其他函数
};


I have a pretty simple image switcher, which I use for manual images switcher and for carousel. In IE 8 it works strange. In carousel scenario image switches just once, thereafter it's dies. But (!) when I implemented Firebug Lite and try to trace - it's works well, only with firebug on... I tried some tricks, I found, but it's all to no purpose. I have no idea what caused this kind of behavior. How to fix it?

js

function toSlide(wrapper, options){
    var active = $('#' + wrapper + ' div.active');
    var slide;
    var direction;

    if (active.length === 0){
        active = $('#' + wrapper + ' div:last');
    }

    if (options === null) {
        options = {};
        options.reverse = false;
        options.animate = false;
    } else {
        options.reverse = options.reverse === null ? false : options.reverse;
        options.animate = options.animate === null ? false : options.animate;
    }

    direction = options.reverse === true ? active.prev() : active.next();

    slide = direction.length ? direction : $('#' + wrapper + ' div:first');

    if (options.animate === true){
        active.addClass('last-active');

        slide.addClass('active')
            .css({opacity:0.0})
            .animate({opacity:1.0}, 1000, function() {            
                active.removeClass('active last-active');
        });
    } else {        
        slide.addClass('active');
        active.removeClass('active');
    }
}

function startSlideShow() {
    setInterval(function(){ toSlide('slideshow', {'animate': true}); }, 5000);
};

window.onload = function() {  
    if (document.location.pathname == '/'){startSlideShow();};
};

html in head

<!--[if IE 8 ]>  
<link rel="stylesheet" href="{{ MEDIA_URL }}css/ie8.css" type="text/css" media="screen, projection" />  <html lang="en" class="no-js ie8"> 
<script defer src="ie_onload.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="{{ MEDIA_URL }}js/jquery-1.6.2.js"%3E%3C/script%3E'))</script> 
<script type="text/javascript" src="http://fbug.googlecode.com/svn/lite/branches/firebug1.3/content/firebug-lite-dev.js"></script>
<![endif]-->

in bottom of html

<!-- Grab Google CDN's jQuery. fall back to local if necessary -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<!-- <script>!window.jQuery && document.write(unescape('%3Cscript src="{{ MEDIA_URL }}js/jquery-1.4.2.js"%3E%3C/script%3E'))</script> -->

<!-- scripts concatenated and minified via ant build script-->
<script src="{{ MEDIA_URL }}js/plugins.js"></script>
<script src="{{ MEDIA_URL }}js/script.js"></script>
<!-- end concatenated and minified scripts-->

解决方案

The cause was non-functional window.onload in IE8. I did right trick but made stupid mistake. So, I fixed it:

was

<!--[if IE 8 ]>
    <script defer src="ie_onload.js"></script>
<![endif]-->

is now

<!--[if IE 8 ]>  
    <script defer src="{{ MEDIA_URL }}js/ie_onload.js"></script>
<![endif]-->

in ie_onload.js

document.body.onload = function() {
    imageViewer();
    // and other functions
};

这篇关于在IE8中不工作window.onload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆