Pages

Friday, November 29, 2013

Javascript-Fire event on resolution change

In the era of responsive websites sometimes it is needed to fire an event on change of resolution.

My designer was stuck in one such scenario and we sorted the same out as follows


 <script>  
 $(document).ready(function () {  
 var width = screen.width,  
 height = screen.height;  
 setInterval(function () {  
 if (screen.width !== width || screen.height !== height) {  
 width = screen.width;  
 height = screen.height;  
 $(window).trigger('resolutionchange');  
 }  
 }, 50);  
 }());  
 $(window).bind('resolutionchange', heightchanges)  
 function heightchanges(){  
 /*Your code on resolution change event here*/
 }  
 });  
 </script>  

HTML-Input Field that accepts only number

If you are looking for a Html Input field that accepts only number on basis of regular expression here is the code


 <input name="number"  
 onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')">