javascript to detect orientation and device

//orientation

var orientation =”;
var win_width = $( window ).width();
var win_height = $( window ).height()

if( win_width > win_height )
{
     $(“html”).removeClass(‘portrait’);
     $(“html”).removeClass(‘landscape’);

     $(“html”).addClass(‘landscape’);
     orientation=’landscape’;
}
else
{
     $(“html”).removeClass(‘portrait’);
     $(“html”).removeClass(‘landscape’);

     $(“html”).addClass(‘portrait’);

     orientation=’portrait’;
}
//device

var mob_min = 0;
var mob_max = 767;; /*480; /*600px; /*767px; /*480px;*/

var tab_min = mob_max;
var tab_max = 1024;

var pc_min = tab_max;

if(orientation==’landscape’)
{
     if(win_width <= mob_max)
     {
          set_device('MOBILE');
     }
     else if(win_width <= tab_max)
     {
          set_device('TAB');
     }
     else
     {
          set_device('PC');
     }
}
else
{
     if(win_height <= mob_max)
     {
          set_device('MOBILE');
     }
     else if(win_height <= tab_max)
     {
          set_device('TAB');
     }
     else
     {
          set_device('PC');
     }
}
Author: bm on January 10, 2014
Category: jquery