Quick Post : Screen Resolution Question

Last Updated on Thursday, 14 May 2009 07:14 Written by Admin Thursday, 14 May 2009 07:14

Hello, Someone via messenger asked us the followinq question.

Hi,
We need to show screen resolution in mrStudio. Please guide us on the same.
Currently i have implemented as below, but is not working.
<a href='JavaScript:var res=screen.width; var res1=screen.height;
   document.write(res + 'x' + res1);'>Click for your screen resolution</a> 

And the answer is ,put this code in you template ..

<a href='JavaScript:var res=screen.width; var res1=screen.height;
   alert(res.toString() + "x" + res1.toString());'>
      Click for your screen resolution</a>

what was wrong ? Well you where trying to add strings to numeric’s with the following code .. (res + ‘x’ + res1) .. res and res1 are numbers and you cannot add text to numbers without converting them first. Hope it helps.

VN:F [1.9.22_1171]
Rating: 6.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Quick Post : Screen Resolution Question, 6.0 out of 10 based on 1 rating

4 Comments

  1. Roger Bateman   |  Friday, 15 May 2009 at 2:33 am

    The issue was not adding a number to a string (although poor programming, Javascript renders this correctly). The error in the original code is that they had nested ‘ – one set around the javascript code and one around the x. You need to use ” inside of ‘ or the other way around (tested in IE7).

    The following code renders correctly:

    <a href='var res=screen.width; var res1=screen.height;
    document.write(res + "x" + res1);'
    rel="nofollow">Click for your screen resolution</a>

    I personally would have written:

    <a href='var res=screen.width; var res1=screen.height;
    document.write("" + res + "x" + res1);'
    rel="nofollow">Click for your screen resolution</a>

    , just for clarity and to ensure that + is interpretted as concatenation.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  2. Smarter Dimensions Team   |  Friday, 15 May 2009 at 9:44 am

    This is a good point thanks Roger.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  3. spk   |  Friday, 18 January 2013 at 11:50 am

    Guys,
    Have you an idea how to push information about resolution to mrStudio? I want to change layout based on screen resolution. Using this method or innerHtml javascript only show information but how can i use it, not only show.

    Regards,
    spk

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  4. Admin   |  Tuesday, 29 January 2013 at 7:13 pm

    Hi spk, do you need to capture the screen resolution ? If yes , searh the blog for the browser sniffer example. That should show you how to work it out.

    VN:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a Reply