Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat value is screen.width if there is no screen? e.g. bots
    primarykey
    data
    text
    <p>I've got a conditional if statement that should detect if the client has a screen dimension (as opposed to a bot) but always seems to return true:</p> <pre><code>var screenWidth = screen.width, screenHeight = screen.height; // Used elsewhere if (screenWidth &gt;= 1) { // Collate screen size } else { // Do other stuff } </code></pre> <p>As I say, the snippet above <strong>always returns true</strong> and the 'Collate screen size' code is run.</p> <p>I've tried</p> <pre><code>if (screenWidth) { ... if (screenWidth != null) { ... if (screenWidth != '') { ... if (screenWidth === '') { ... if (typeof screen === 'object') { ... if (typeof screenWidth === 'number') { ... </code></pre> <p>All with no success.</p> <p>Yet in my text file (old school I know) I'm getting the following:</p> <pre><code>1385466873 | | x | | ^ </code></pre> <p>Which makes me think the value assigned to the variable is empty!?</p> <p>For reference, I get the following for 'real' browsers:</p> <pre><code>1385465703 | Mac OS X 10.8.4 | 1440 x 900 | undefined | MacIntel ^^^^ </code></pre> <p>See more here: <a href="http://browsertrend.info/client.txt" rel="nofollow">http://browsertrend.info/client.txt</a></p> <hr> <p><strong>More info:</strong></p> <p>Having added the screen.width typeof to the output I now get:</p> <pre><code>1385485905 | Windows 7 | number | 1200 x 1600 | undefined | Win32 ^^^^^^ </code></pre> <p>And nothing, as below:</p> <pre><code>1385485903 | | | x | | ^ </code></pre> <p>So surely testing for:</p> <pre><code>if (typeof screenWidth === 'number') { ... </code></pre> <p>should have worked?</p> <hr> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload