Skip to main content

How to do Everything in Javascript (Pure JS)

Mobile user-agent detection

var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android()
|| isMobile.BlackBerry()
|| isMobile.iOS()
|| isMobile.Opera()
|| isMobile.Windows());
}
};

if (isMobile.Android()) {
document.location.href = "y";
} else if(isMobile.iOS()) {
document.location.href = "x";

jQuery UI Datepicker Reset Date

$(document).ready(
function () {
$(.datepicker).datepicker({
showOn: 'focus', showButtonPanel: true,
closeText: 'Clear', // Text to show for close button
onClose: function () {
var event = arguments.callee.caller.caller.arguments[0]; // If Clear gets clicked, then really clear it
if ($(event.delegateTarget).hasClass('ui-datepicker-close')) {
$(this).val('');
}
}
});
});

Convert object to string

Use JSON.stringify() function:

var obj = new Date();
console.log(JSON.stringify(obj)); 

DataTables Editor jQuery UI Datepicker Issue

  • When 2 datepickers are used, it will jump to first datepicker when the second datepicker's date is selected. Make sure that datepickers aren't used as the first field.

Problem: DataTable - Cannot read property 'style' of undefined jquery.dataTables.js

Make sure that HTML number table columns matches the number of 'mData' definition during data table initialization