Kozuch
Kozuch

Reputation: 2292

JavaScript+Phonegap+Android: screen.width returns bad (almost random) values

After launching app with "deviceready" event, my Phonegap app on Android returns false screen.width (window.innerWidth is the same) values on ZTE Blade (native 800px). I get width values like 320, 533 or 787 px, sometimes different values within one app instance (launch) when asking multiple times...

I have android:screenOrientation="landscape" in my AndroidManifest.xml. Using Phonegap/Cordova 1.8.1 in Eclipse (Indigo).

Some sample values of screen.width:

in index.html

then redirect three times (change window.location to different HTML file) because of 2 splash-screens and finally land to main.html. I include my .js code in every file just for debugging, and get 3 console.logs:

  1. 320
  2. 787
  3. 787

Very strange...

Upvotes: 3

Views: 3515

Answers (1)

Samuli Hakoniemi
Samuli Hakoniemi

Reputation: 19059

There's a comprehensive article (+ comparison tables of different values) that you should read: http://tripleodeon.com/2011/12/first-understand-your-screen/

Hope this helps with your issue.

Upvotes: 2

Related Questions