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

99封情书 提交于 2019-12-06 08:27:36

问题


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

  • before document.addEventListener+"deviceready": 320
  • just after "deviceready": 320

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...


回答1:


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.



来源:https://stackoverflow.com/questions/11524669/javascriptphonegapandroid-screen-width-returns-bad-almost-random-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!