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.
Quick Post : Screen Resolution Question,
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.
This is a good point thanks Roger.
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
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.