TIMEAGO FUNCTIONALITY USING JQUERY.TIMEAGO PLUGIN NOT WORKING IN IE & MOZILLA

Kamlakar Singh

Total Post:194

Points:1396
Posted by  Kamlakar Singh
 2612  View(s)
Ratings:
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.

  1. Pawan Shukla

    Post:38

    Points:274
    Re: TimeAgo functionality using jquery.timeago plugin not working in IE & Mozilla

    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());

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!