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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:27:20+00:00 2026-05-25T19:27:20+00:00

This is weird. I’m using javascript to figure the resolution in a web page.

  • 0

This is weird. I’m using javascript to figure the resolution in a web page. For that I have a following function (somewhat simplified for this purpose):

function check() {
    var win = document.defaultView || document.parentWindow,
        ratio = win.devicePixelRatio ? win.devicePixelRatio : 1,
        h = win.innerHeight,
        w = win.innerWidth,
        root = document.documentElement;

    if (!h) {
        h = root.clientHeight;
        w = root.clientWidth;
    }
    alert("height/width/ratio; " + h + "/" + w + "/" + ratio);

}

on android devices there seems to be a really peculiar behaviour:

I’ll give a Nexus S as an example but obviously I’ve verified this on many other Android devices running different versions.

If you arrived to the page containing the script above by clicking on a link in an email app (gmail or outlook), the alert will yield 1130/800/1.5 (height and width are way too high). This is consistent. Now, if you go to the address bar and edit the url (add/remove a parameter or parameter value) and hit “Go”, the exact same code will yield 452/320/1.5 (thats more like it, and that’s also consistent).

How and why on earth is this happening?

EDIT: worth noting is that so far this only seems to apply to devices with devicePixelRatio > 1, i.e. not older Android phones on v 1.5 / 1.6

  • 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-05-25T19:27:21+00:00Added an answer on May 25, 2026 at 7:27 pm

    After a lot of searching and debugging, this almost seems like a bug.

    The repro is easy: if the above script is run synchronously in onload event and you click on something that opens a new window, email app or a web page with target=_blank, both screen and window width and height properties will be wrong. Makes no difference if you use jQuery, YUI or plain javascript.

    The solution/workaround is to wrap the method called in onload in a setTimeout() with timeout set to 0. That will run the method asynchronously and yield correct result.

    <body onload="setTimeout(check, 0);">
    

    That, my friends, closes this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this weird crash that only happens when running the app on the
I have this weird bug, where C++ calls the wrong function: So this bit
I have this weird issue in Magento when someone places an order using PayPal
I have this weird issue with special characters. In JSP, I am using field
So I have this weird issue that i am hitting, i have a slide
I am getting this weird exception and I have no clue how to figure
I've seen this weird behavior on several sites recently: I scroll down a page
I'm experiencing this weird problem which my scrollbar jumps by itself to somewhere that
I have this weird problem with setting up cookies with PHP. Everything worked fine
Today, I ran into this weird problem with a user using Mac OS X.

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.