开发者

how to fix javascript error in ie7/8?

if you open the page: http://www.rhino.com/shop/product/the-monkees-the-birds-the-bees-the-monkees-boxed-set you will see at the bottom of the page, a next and previous buttons, these are navigation buttons, they work fine in firefox but in ie the style is removed from the page when they are clicked!. please 开发者_如何学运维advise on what might be the cause of the problem. i have already spent hours debugging :(


When I debug it on IE8, I see a runtime error here:

cd=new Date();

Most likely this does not accord with this piece of HTML:

<li id="cd" class=""><a href="#productInfo-cd">CD</a></li>

IE 'helpfully' launches elements with an id as global variables. So cd is actually a <li> element, and IE doesn't like it if you assign new Date() to it. It would be perfectly fine if IE would treat cd as a normal local variable, but it does not, hence the runtime error.

This piece of code is inside a anonymous function which is really nasty (shown below). But the solution is simple: just write proper functions, and declare your variables. If the anonymous function would have used one line in the top declaring variables like this:

var cd, dc, ...other variable names... ;

it would have worked just fine, because then the cd variable inside the function would have referred to the local variable, not the global cd element which IE thinks referes to the li element with id="cd".

Now it is entirely possible that this is just one of many problems with this page. But I am assuming the first error encountered by IE stopped execution of the remainder of your script, which why some of it diddn't work.

function anonymous(t, z, y) {
  dc=new Date('1/1/2000');f=15;ne=8;
  if(dc.getDay()!=6||dc.getMonth()!=0){
    return'Data Not Available'
  }else{;
    z=parseInt(z);
    if(y=='2009'){f=8;ne=1};
    gmar=new Date('3/1/'+y);
    dsts=f-gmar.getDay();
    gnov=new Date('11/1/'+y);
    dste=ne-gnov.getDay();
    spr=new Date('3/'+dsts+'/'+y);
    fl=new Date('11/'+dste+'/'+y);
    cd=new Date();
    if(cd>spr&&cd<fl){
      z=z+1
    }else{
      z=z
    };
    utc=cd.getTime()+(cd.getTimezoneOffset()*60000);
    tz=new Date(utc + (3600000*z));
    thisy=tz.getFullYear();
    var days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    if(thisy!=y){
       return'Data Not Available'
    }else{;
       thish=tz.getHours();
       thismin=tz.getMinutes();
       thisd=tz.getDay();
       var dow=days[thisd];var ap='AM';var dt='Weekday';
       var mint='00';
       if(thismin>30){mint='30'}
       if(thish>=12){ap='PM';thish=thish-12};
       if (thish==0){thish=12};
       if(thisd==6||thisd==0){dt='Weekend'};
       var timestring=thish+':'+mint+ap;
       var daystring=dow;
        var endstring=dt;
       if(t=='h'){
          return timestring}
       if(t=='d'){
           return daystring};if(t=='w'){return endstring}}};
   }

Now debugging where this is comming from is a bit of a prob. My callstack reads:

anonymous   JScript
s_doPlugins JScript
    anonymous function  JScript
global code JScript

The top one is where the actual error occurs.

The root where this is all happening is here:

    /************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
    var s_code=s.t();if(s_code)document.write(s_code)

Somehow, from here, s_doPlugins is called which contains the actual call to the anonymous function that is causing the trouble. It looks like s_doPlugins is located in s_code.js. If I step through that, I find that the trouble is in this line:

s.prop9=s.getTimeParting('h','-5','2008'); // Set hour 

which is line 38 of s_code.js. With a little bit more poking around, I find it is actuall this plugin:

/*
* Plugin: getTimeParting 1.3 - Set timeparting values based on time zone
*/
s.getTimeParting=new Function("t","z","y",""
+"dc=new Date('1/1/2000');f=15;ne=8;if(dc.getDay()!=6||"
...more crap here...

This is at line 95 in s_code.js

As a quick fix i would probably comment out all calls to s.getTimeParting() in s_doPlugins() in s_code.js and see if that fixes your problem. Then, the long and hard but noble taks remains of churning something sensible out of this mess :))


I found this infuriating and discovered that the problem was my site using a div with the ID "utc", which clashes with the s_code JS. 'UTC' is time-related so I can only assume that there's sloppy JS relying on it being something else if present at all!


With 2021 soon upon us, I wanted to resurface an issue with older versions of the getTimeParting plug-in that made quite the stir at the beginning of this year. If you took the easy route and edited the plug-in code instead of upgrading to the latest version, you'll want to make sure that you make those same edits again before January 1.

More information on this topic can be found in this forum thread:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜