I was trying to use the post time updating script posted here. It works great, except that on Mobile Safari it generates NAN errors. I tried to print out each of the variables to see where the NAN is coming from, but no dice. If somebody could possibly help me figure out where the error is generated I should be able to figure out a fix. Or even help me figure out how I could best find where the error is coming from. The actual code is below.
<script src="js/jquery-1.6.3.min.js"></script>
<script>
$(document).ready(function(){
$.fn.UpdateSince = function(interval) {
var times = this.map(function(){ return { e: $(this), t: parseInt($(this).html()) }; });
var format = function(t) {
if (t > 60) {
return Math.floor(t / 60) + ' minutes ago'
} else {
return t + ' seconds ago';
}
}
var update = function(){
var now = new Date().getTime();
$.each(times, function(i, o){
o.e.html(format(Math.round((now - o.t) / 1000)));
});
};
window.setInterval(update, interval);
update();
return this;
}
});
</script>
<script>
$(document).ready(function(){
$('.TimeSince').UpdateSince(1000);
});
</script>
Edit: Mobile Safari debug console shows no errors, but all output integers are NaN.
My guess is that it’s here:
If
$(this).html()is empty, it will fail.