Posted about 9 years ago. Visible to the public.

Detect effective horizontal pixel width on a mobile device with Javascript

So you want to find out how many horizontal pixels you have available on a mobile device. This is super difficult because:

Many Bothan spies had to die for this code:

Copy
function effectiveDeviceWidth() { var deviceWidth = window.orientation == 0 ? window.screen.width : window.screen.height; // iOS returns available pixels, Android returns pixels / pixel ratio // http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html if (navigator.userAgent.indexOf('Android') >= 0 && window.devicePixelRatio) { deviceWidth = deviceWidth / window.devicePixelRatio; } return deviceWidth; }

Flaky tests are tests that sometimes fail for no obvious reason. They are the plague of many end-to-end (E2E) test suites that automate the browser through tools like Capybara and Selenium.

Join our free training event and learn to fix any flaky test suite, even in large legacy applications.

Owner of this card:

Avatar
Henning Koch
Last edit:
about 9 years ago
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more