//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;
Category: Javascript
In PHP to have "Variable" variables. For example $x = "variable"; $$x = "hello, world!"; echo $variable;" //"hello, world!" So as a workaround you can do as the following: var obj = {} obj.foo = 42; var bar = 'foo'; console.log(obj[bar]);
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
if (typeof FileReader !== "undefined") { var size = document.getElementById('upload_file').files[0].size; size = Math.round(size / 1024); console.log(size+' KB'); }
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?
if ( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) { //if ajax request your code runs here } else{ //if not an ajax request your code runs here }
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 ?
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
//reload 1 iframe $('#iframe').contentWindow.location.reload(true); //reload all iFrames $('iframe').each(function() { this.contentWindow.location.reload(true); }); //by changing source to the same source $('iframe').attr('src', $('iframe').attr('src'));
I had a problem in a page that gets it's content via an ajax request and place the result of the ajax request in a slider, I was testing it on other browsers, and It came to IE, passed IE9 and IE8, and when it came to IE7 I couldn't see the slider with it's … Continue reading Javascript parsing issue on IE7