不工作窗口。onload在IE8

时间:2023-01-17 13:06:29

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?

我有一个非常简单的图像切换器,我用它来手动图像切换器和旋转木马。在IE 8中,它工作起来很奇怪。在carousel场景中,图像切换一次,然后它就消失了。但是,当我执行Firebug Lite并尝试跟踪时,它的效果很好,只有Firebug在…我尝试了一些技巧,但都毫无用处。我不知道是什么导致了这种行为。如何修复它吗?

js

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

html头

<!--[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

在底部的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-->

2 个解决方案

#1


1  

Accessing console in FF without Firebug open or in IE will result in an error that will block the rest of your JS from executing. If you want to leave calls to console in, you should implement them like one of the following:

在不打开Firebug或IE的情况下访问控制台,将会导致一个错误,这将阻塞您的其他JS执行。如果您想要对控制台进行调用,您应该将其实现如下所示:

try { console.log('blah'); } catch(e) {}
// or
if (typeof console != 'undefined') console.log('blah');

Or use a custom built logging function that implements something like the above.

或者使用一个定制的日志功能来实现类似上述的功能。

#2


0  

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

原因是没有功能的窗口。在IE8 onload。我做错了,但犯了愚蠢的错误。所以,我固定它:

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

在ie_onload.js

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

#1


1  

Accessing console in FF without Firebug open or in IE will result in an error that will block the rest of your JS from executing. If you want to leave calls to console in, you should implement them like one of the following:

在不打开Firebug或IE的情况下访问控制台,将会导致一个错误,这将阻塞您的其他JS执行。如果您想要对控制台进行调用,您应该将其实现如下所示:

try { console.log('blah'); } catch(e) {}
// or
if (typeof console != 'undefined') console.log('blah');

Or use a custom built logging function that implements something like the above.

或者使用一个定制的日志功能来实现类似上述的功能。

#2


0  

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

原因是没有功能的窗口。在IE8 onload。我做错了,但犯了愚蠢的错误。所以,我固定它:

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

在ie_onload.js

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