Home > DeveloperSection > Forums > TimeAgo functionality using jquery.timeago plugin not working in IE & Mozilla
Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    October-30-2014 8:09 AM

 JavaScript Jquery Plugins  Knockout.js  Timeago 
Ratings:


 1 Reply(s)
 1781  View(s)
Rate this:

I am trying to add a functionality of timeago in my application by using jquery.timeago plugin. I am using knockout binding to display the list of times.

It is working fine in chrome but it is not able to display data in other browsers.

Here is my script code:

    <script src="Scripts/jquery-2.1.1.min.js"></script>

    <script src="Scripts/knockout-3.2.0.js"></script>

    <script src="Scripts/jquery.timeago.js"></script>

 

    <script>

 

        $(function () {

 

            var viewModel = {

 

                arr: [{

                    msgdate: new Date()

                }, {

                    msgdate: new Date()

                }]

            };

 

            ko.bindingHandlers.timeago = {

                update: function (element, valueAccessor) {

                    var value = ko.utils.unwrapObservable(valueAccessor());

 

                    var $this = $(element);

 

                    $this.attr('title', value);

 

                    if ($this.data('timeago')) {

                        var datetime = $.timeago.datetime($this);

                        var distance = (new Date().getTime() - datetime.getTime());

                        var inWords = $.timeago.inWords(distance);

 

                        $this.data('timeago', { 'datetime': datetime });

                        $this.text(inWords);

                    } else {

                        $this.timeago();

                    }

                }

            };

 

            ko.applyBindings(viewModel);

        });

 

    </script>

 

 

Html part is given below:

 

<div data-bind="foreach: arr">

        <div class="timeago" data-bind="timeago: msgdate"></div>

</div>

 

Example is here is fiddle also:

http://jsfiddle.net/ugqkd60p/

 

Please help me to solve it.

Thanks.



Pawan Shukla

Total Post:37

Points:267
Posted on    October-30-2014 8:13 AM

Anyway jquery.timeago has explicit support for the iso8601 date format so just use the toISOString method which will work in all of the browsers:

$this.attr('title', value.toISOString());

Don't want to miss updates? Please click the below button!

Follow MindStick