开发者

jQuery Countdown not working with all versions of IE

I am using jquery countdown in one of rails project with following code -

var timeoff = new Date("#{time_format(auction.end_time)}");
$("#myDivId .timerContent").countdown({until : timeoff, onExpiry:applySold, compact : true, layout : '', serverSync: serverTime });

and serverTime methods has -

 function serverTime(){
    $.get("/server_time","", function(data){
      time = new Date(data);
    }, "text");
  return time;

}

This code works very well with firefox, safari and chrome but doesn't work in IE. In IE it renders this - Nan:NaN:NaN

What might be causing this ?

P.S. In above code i at the point of var timeoff = new Date("#{time_format(auction.end_time)}");

i have time format as - "2011-07-07T00:00:00+05:30"

and my Doc type is set as -

    <!DOCTYPE htm开发者_运维百科l PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


I have the exact SAme ISSUE, im using Date.parse($(".time").html) which outputs fine for both IE and FF... When I test this in plain HTML it works and counts down for BOTH BROWSERS!! But Its seems RUBY rials.js or the load order of the JS's are conflicting with IE..!!!!!

Test this page at www.scratch22.net/testing in BOTH IE and FIREFIOX!! works fine!! but not from within an actual rails app!!

EDIT So I tried many many different answers from many different places and could only get one to work for comparing datetime with timezone in javascript for IE

    ruby-1.9.2-p180 :001 > Time.now
        => 2011-07-14 08:55:26 +1000 
    ruby-1.9.2-p180 :002 > Time.now.to_s
        => "2011-07-14 08:55:30 +1000" 
    ruby-1.9.2-p180 :004 > Time.now.to_datetime.to_s 
        => "2011-07-14T08:55:51+10:00"
    ruby-1.9.2-p180 :005 > Time.now.to_formatted_s 
        => "2011-07-14T08:56:18+10:00"
    ruby-1.9.2-p180 :003 > Time.now.to_datetime
        => Thu, 14 Jul 2011 08:55:35 +1000

** I originally had <%= Time.now.to_datetime %> and didnt realise that this returns a different string format when printing out to a page **

    ruby-1.9.2-p180 :007 > Time.now.to_formatted_s(:rfc822)
        => "Thu, 14 Jul 2011 08:57:26 +1000"

The last Was the only time format with timezone that I could get IE to work with as a number... I got rid of the Parse aswell...

All up what I wanted to do was return the time between now and when a price should drop, and show a countdown...

Resulting JS was something like

    now = new Date().getTime(); // Thu, 14 Jul 2011 07:57:26 +1000
    drops_in = new Date("Thu, 14 Jul 2011 08:57:26 +1000").getTime(); //1 hour in future
    countdown = drops - now;
    $(".counter_holder").html(format_time(countdown)); // 00:35:25

inside of a interval updating every 500 milliseconds

The lesson learnt...

    ruby-1.9.2-p180 :003 > Time.now.to_datetime

is not the same as

<%= Time.now.to_datetime %>

Use <%= Time.now.to_formatted_s(:rcf822) %> instead

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜