Javascript: stop submitting form on pressing ENTER key


//stop submitting form on pressing enter key //This code will allow enter key on textarea function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type=="text")) {return false;} } document.onkeypress = stopRKey;

jQuery Colorbox: Hide background page vertical scroll bar on open


To hide the scroll bar of the background page when the colorbox opens "like facebook for example"   /* make the page scroll dissapear when colorbox is open and retrieved back when colorbox is closed */ var screen_position; $(document).bind('cbox_open', function() { screen_position = $("body").scrollTop(); $('body').css({ overflow: 'hidden' }); $("body").scrollTop(0); }).bind('cbox_closed', function() { $('body').css({ overflow: 'auto' … Continue reading jQuery Colorbox: Hide background page vertical scroll bar on open

How can I check if a jQuery plugin is loaded?


Generally speaking, jQuery plugins are namespaces on the jQuery scope. You could run a simple check to see if the namespace exists: if(jQuery().pluginName) { //run plugin dependent code } ,If we're talking about a proper jQuery plugin (on that extends the fn namespace), then the proper way to detect the plugin would be: if($.fn.pluginname != … Continue reading How can I check if a jQuery plugin is loaded?

How to know the mode the browser running with ?


How to know the mode the browser running with ? i.e. Standards Mode, Quirks Mode ...   In Firefox and Opera you can determine if your browser is in "quirks mode" by checking page info. Using document.compatMode, will tell you the mode you are in with most browsers. In Chrome, Safari, and IE, run this javascript in the address … Continue reading How to know the mode the browser running with ?

Javascript: Easily calculate difference between two dates in days


Date.daysBetween = function( date1, date2 ) { //Get 1 day in milliseconds var one_day=1000*60*60*24; // Convert both dates to milliseconds var date1_ms = date1.getTime(); var date2_ms = date2.getTime(); // Calculate the difference in milliseconds var difference_ms = date2_ms - date1_ms; // Convert back to days and return return Math.round(difference_ms/one_day); } //date1 and date2 are Date … Continue reading Javascript: Easily calculate difference between two dates in days