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 8985155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:16:11+00:00 2026-06-15T21:16:11+00:00

Disclaimer: I am not a javascript or jQuery expert. This is probably an easy

  • 0

Disclaimer: I am not a javascript or jQuery expert.

This is probably an easy problem to solve, as it’s just a small fix I can’t figure out. I am implementing a site that is horizontal if the browser is in landscape mode, and vertical if in portrait. CSS changes are not an issue as that is easy with media queries. The problem I run into is when I want to only run a specific script when the screen is in landscape mode. Next problem I run into is that I don’t just want this to work on mobile, but I also want it to be responsive in a standard browser as well; i.e. detect when the screen width > screen height and run said script. Here is my code so far:

var height = $(window).height();
var width = $(window).width();
if (width > height) {
    //run landscape script
} else {
    //run portrait script
};

This is working just fine to detect orientation when the page loads, but it doesn’t change when the screen is resized since the script is not bound to window.resize. That being said, it is also not working when I bind it to window.resize.

Is there a better way to go about this? Or do I just need to fix up what is already here?

  • 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-15T21:16:12+00:00Added an answer on June 15, 2026 at 9:16 pm

    In case somebody else runs into this problem in the future, I’ll post what solved my problem.

    When I attempted to add the resize event to the function, my code looked like this:

    $(window).on('resize', function() {
        var height = $(window).height();
        var width = $(window).width();
        if (width > height) {
            //run landscape script
        } else {
            //run portrait script
        };
    )};
    

    This worked just fine, but it did not appear that way because the script was only being fired when the browser resized. While this is essential, the script also needs to fire when the page loads. My solution was just to add ‘load’ to the event:

    $(window).on('resize load', function() {
        var height = $(window).height();
        var width = $(window).width();
        if (width > height) {
            //run landscape script
        } else {
            //run portrait script
        };
    )};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: I am anything but a Javascript expert, so I'm not even sure if
Disclaimer: Do not try this at home Why, if I am using jQuery, does
DISCLAIMER: This is not a real-world example. It is just a theoretical question of
First off, I need to give a disclaimer: DO NOT RUN THIS JAVASCRIPT It
Disclaimer: I am trying to learn javascript. I am not a clever man. So,
Disclaimer: not sure this is WordPress related or not. I'm following a simple tutorial
(DISCLAIMER: I'm not a programmer, I spend my time on serverfault, I'm just a
Disclaimer: I'm not a c++ developer, I can only do basic things. (I understand
Disclaimer: this is not a question about how to install asp.net or an application
(Disclaimer - I'm not the database designer. I'm just the poor developer what has

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.