I have written this script based on other scripts i have read about, and take into consideration i'm a novice to js / jquery.
I want to detect the size and orientation of the device on page load and on orientation change.
So that i can apply different rules on each situation.
It works great on android devices, but i found it didnt work in portrait mode on ipad's Now i cant figure out what i did wrong. Even on js lint i get that all my scripting is not set and so on. a bit of help would be nice. This is the code i have written.
This code is only triggered if it detects your on a mobile device using php
$(document).ready(function(){
var height = $(window).height();
var width = $(window).width();
if ( $(window).width() < 768) {
if(width>height) {
// Smartphone Landscape Rules
var orientation = ' Landscape';
}else{
// Smartphone Portrait Rules
var orientation = ' Portrait';
}
alert ('Smartphone '+width+' - '+height+orientation);
}
if ( $(window).width() > 768) {
if(width>height) {
// Tablet Landscape Rules
var orientation = ' Landscape';
}else{
// Tablet Portrait Rules
var orientation = ' Portrait';
}
alert ('Tablet '+width+'-'+height+orientation);
}
$(window).resize( function(){
var height = $(window).height();
var width = $(window).width();
alert (width+' - '+height);
if ( $(window).width() < 768) {
if(width>height) {
// Smartphone Landscape Rules
var orientation = ' Landscape';
}else{
// Smartphone Portrait Rules
var orientation = ' Portrait';
}
alert ('Smartphone '+width+'-'+height+orientation);
}
if ( $(window).width() > 768) {
if(width>height) {
// Tablet Landscape Rules
var orientation = ' Landscape';
}else{
// Tablet Portrait Rules
var orientation = ' Portrait';
}
alert ('Tablet '+width+'-'+height+orientation);
}
});
});