Coldfusion - detect visitor's pc resolution - (screen size)

Can anyone tell me how I can detect the visitor pc's screen size/resolution?
I've searched ee and found a mention below:

but they say it can only be done in javascript.? excuse ignorance ... but how do I pass the javascript variable into that of a CF variable?

I'm a total newbie .. so.

In other words ... I'm trying to determine the width & height of client pc screen size.

Thanks much!
Richard Buchanan
The Opinion Exchange

Who is Participating?
Seth_BienekConnect With a Mentor Commented:

You can only detect browser resolution using client-side (ie JavaScript) programming.  There are two ways to get the data from client-side code to CF: by passing the data in the URL, or by posting the data in a form.

If you have a login page on in your app, then a good way to do this is using the form-based approach.  Just add a hidden form element (or two) within your <form> tags on the login page:

<input type="hidden" name="screenprops" value="">

And then some Javascript to populate the hidden form field with the screen information you want, further down the page (toward the end is good):

<script type="text/javascript" for="window"  event="onload()">
  document.form1.screenprops.value = screen.width + ' X ' + screen.height + ' (' + screen.colorDepth + ')';

Then, when the user submits the login form, the hidden form field gets passed along with the login information to the login action page as form.screenprops.

This has been the more straightforward approarch in my experience.  If you want instructions on doing it via url forwarding, or if you have any questions about this approach, just holler.

Also, as a caveat, the javascript provided here has been simplified for illustrative purposes, and some error-checking and cross-browser compatibility code has been removed.

Take Care,

1st what is the reason for wanting to know the resolution and pass it on to ColdFusion?

Then to pass any variable from JavaScript o ColdFusion you'll have to make a new page call, either with GET or POST, you can pass the variable you want coldfusion to know about via the URL or as a FORM field, i.e. test

<form ........>
<input type="hidden" name="myjsvariable" value="a test">
<input type="submit ........>

Then in coldfusion you can reference to these variables like so

#url.myjsvariable# or #form.myjsvariable#

Does that help and make sense?
couldnt you just use the cfscript tag to set a CF variable?

      function ListFix(list) {
        list = replace(list,"#delim##delim#", "#delim##null##delim#", "ALL");
        list = replace(list,"#delim##delim#", "#delim##null##delim#", "ALL");

list being the variable?

Good luck.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

rcbuchananAuthor Commented:
i feel compelled to inform you that i'm BEYOND newbie.
I'm CF self-taught ... with bad habits and missing gaps.
i'm truly lost on this one! ListFix!?
You and me too, I am lost too, I can't see how what Cypher suggests has anything to with your question, no offense Cypher...

Simple answer to your question, ColdFusion can only talk to CF if you GET or POST variables to CF, i.e. you pass the js variables to it via url or form variables.

To detect screen resolution you would need to use JavaScript
Sorry that was some code that i used in a completey differnet app, I have spent some time trying to work your answer out but it looks like im at a lost

you have to pass the information through a url effectivly reloading your page.

I presum this is for different templates of your site, the only idea i could give you is to load a small window or something to detect the browser size.

Sorry I cant be much more of a help
Good luck
client related stuff can be detected using javascript.

after detecting it assign it to a form hidden field and submit the form.
on the next page u can use this value as a normal form.field.

and to detect screen resoltion , its one line code for getting the width and height.

rcbuchananAuthor Commented:
Ok, finally got to a position in development to actually apply this answer to my code!
All I can say is VERY VERY cool!

Thank you very much!
Richard Buchanan
The Opinion Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.