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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:43:17+00:00 2026-06-02T17:43:17+00:00

The meta tag viewport lets me set up the initial scale for a website,

  • 0

The meta tag “viewport” lets me set up the initial scale for a website, but this can get weird if the user then flips the orientation of the device.

For example, if I set the scale to be 800×380 and the user opens the website in portrait mode, this scale is obviously wrong, and when the user rotates 90deg, the website ends up being more like 1650 wide.

How would I set a viewport such that if the device is landscape to begin with, it’s 800×380, and if it’s portrait to begin with, it’s 380×800?

  • 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-02T17:43:19+00:00Added an answer on June 2, 2026 at 5:43 pm

    To detect orientation change, attach an event listener to the window:

    window.addEventListener('orientationchange', updateOrientation, false);
    

    In the updateOrientation function you can detect which orientation the device is in and reset the viewport attributes accordingly:

    function updateOrientation() {
      if (!(navigator.userAgent.match(/iPhone/i)) && !(navigator.userAgent.match(/iPod/i))) {
        return;
      }
    
      var viewport = document.querySelector("meta[name=viewport]");
    
      switch (window.orientation) {
        case 0: //portrait
          //set the viewport attributes to whatever you want!
          //For Ex : viewport.setAttribute('content', 'width=device-width, initial-scale=1.0, user-scalable=1;');
          break;
        case 90: case -90: //landscape
          //set the viewport attributes to whatever you want!
          break;
        default:
          //set the viewport attributes to whatever you want!
          break;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this meta-tag <meta name=viewport content=width=device-width, initial-scale=1.0, user-scalable=no> And I have a text
Initially I used the meta tag: <meta name=viewport content=width=device-width, initial-scale=1.0/> On using this tag,
I have a added to the viewport meta tag width=device-width,initial-scale=1.0 and on an iPad
I'm trying to get meta tag information for each page on a particular site,
I assumed it was strictly by the meta 'description' tag. But I noticed that
We've got a few pages that use the apple-mobile-web-app-capable meta tag (value=yes), but on
I have an iPhone web application that creates a meta viewport tag dynamically, using
How to change the meta viewport based on device resolution? we can use media
I'm trying to configure a viewport for mobile Safari. Using the viewport meta tag,
I have 2 questions on setting viewport ? Is the meta tag the only

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.