Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:08:29+00:00 2026-06-12T02:08:29+00:00

I have written this script based on other scripts i have read about, and

  • 0

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);
}
});
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:08:30+00:00Added an answer on June 12, 2026 at 2:08 am

    I have found my problem and that is that the if more then rule had to be 1 px less then the actual size to be able to be detected for iPad’s.

    Here is the code if anybody is interested. Just ignore the alerts as i added them to test all orientations and refreshes.

    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() > 767) {
    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();
    
    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() > 767) {
        if(width>height) {
        // Tablet Landscape Rules
        var orientation = ' Landscape';
    }else{
        // Tablet Portrait Rules
        var orientation = ' Portrait';
        }
        alert ('Tablet '+width+'-'+height+orientation);
    }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the script I have written for gzipping content on my site, which
This is a simple script I have written to test command line argument handling:
I've written a script based on a for-loop to read in columns of multiple
I have written quite a few scripts to update my product catalog based on
I have written a PHP script based on a piece of code I've found
I have written this T-SQL script to roll up duplicate rows in a database
have written this little class, which generates a UUID every time an object of
I have written this code inside a servlet to delete certain records from three
I have written this code in JavaScript and works perfectly fine when I include
I have written this function to auto correct gender to M or F from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.