Link to home
Start Free TrialLog in
Avatar of ayudh
ayudh

asked on

Detecting client screen size with ColdFusion

Is there a way for the CF script to detect the user's screen size (in order to serve optimized content)?
Avatar of cfexpert
cfexpert

I don't think there is any way to detect the screen site of the visitor. You may, however, try to find out any custom tag at http://www.allaire.com .

You can detect screen size using JavaScript or ASP. In ASP you can use the following script:

<%

Response.Write Request.ServerVariables("HTTP_UA_PIXELS")
' other info you may like
' This header indicates the number of colors that the browser can display
Response.Write Request.ServerVariables("HTTP_UA_Color")
' This header indicates the type of machine being used to execute the browser.
Response.Write Request.ServerVariables("HTTP_UA_CPU")
' This header indicates the operating system of the computer executing the browser.
Response.Write Request.ServerVariables("HTTP_UA_OS")

%>

but you shouldn't rely on these headers; they are supported oly by the Win '95 versions of IE.
Rajech: where are u from in India.
I am also from india.......

jimmy
here is a javascript that will pull screen resolution and color depth.  you can use this script to pull the variables into a cf-script to insert them into the db.  if the script is not cold fusion to start with you can still call an cfinsert script by using an <img src="insert.cfm?variables=variables" border=0 width=1 height=1>

<script language="javascript">
                  from = ''; JC_screen = ''; JC_color = '';
                  if (document.referrer != '')
                  {from = "from="+document.referrer;}
                  if (screen.width != '')
                  {JC_screen = "&ScreenRes="+screen.width+"x"+screen.height;}
                  if (window.screen.colorDepth != '')
                  {JC_color = "&ColorDepth="+window.screen.colorDepth;}
            </script>

i hope this helps
hanj
this will do I am just giving the thing in javascript it will take the screen resolution and open a window according to it
don't mide for images Ha Ha
<html>
<head>
<title>MuzicaOnline</title>
<meta keywords="Music,Music Shopping,Musical Instruments,Music System,Casstte,CD,DVD,Radio,Music Musium,New Artist,Promoters,Music Academy,Academy">
<script language="JavaScript">
<!--
function getheight()
      {
      height=screen.height
      width=screen.width
if(height==600)
      {high=570}
else
{if(height==480)
      {high=450}
else
      {if(height==786)
      {high=768}
else{high=995}
}}
if(width==640)
      {wide=630}
else
{if(width==800)
      {wide=790}
else
      {if(width==720)
      {wide=710}
else{if(width==1024)
{wide=1014}
else{wide=1270}}}
}
timer=setTimeout("newWindow=open('main.htm','new','toolbar=no,height='+high+',width='+wide+',left=0,top=0,resize=no,alwaysontop=yes,alwaysraised=yes')",3000)
}

//-->
</script>
</head>
<body background="image/background.jpg" onLoad=getheight()>
<table border=0 cellspacing=0 cellpadding=0 align=center height=100%><tr><td nowrap>
<table border=0 cellspacing=0 cellpadding=0 align=center valign=middle><tr><td nowrap>
<table border=0 cellspacing=0 cellpadding=0 align=center><tr><td nowrap valign=top>
<img src="image/note5.gif">
</td></tr></table></tr><tr><td>
<table border=0 cellspacing=0 cellpadding=0 width=100%>
<tr><td><img src="image/note5.gif">&nbsp;&nbsp;</td><td>
<font color=blue size=7><center>W&nbsp;&nbsp;e&nbsp;&nbsp;l&nbsp;&nbsp;c&nbsp;&nbsp;o&nbsp;&nbsp;m&nbsp;&nbsp;e&nbsp;&nbsp;<br> T&nbsp;&nbsp;o&nbsp;&nbsp;<br> M&nbsp;&nbsp;u&nbsp;&nbsp;z&nbsp;&nbsp;i&nbsp;&nbsp;c&nbsp;&nbsp;a&nbsp;&nbsp; Pvt. &nbsp;&nbsp;Ltd.</center></font>
</td><td>&nbsp;&nbsp;
<img src="image/note5.gif"></td></tr></table>
<tr><td nowrap align=center>
<table border=0 cellspacing=0 cellpadding=0><tr><td>
<img src="image/note5.gif"></td></tr></table></td></tr>
</table></td></tr></table>
</body>
</html>
Bye:-)
Avatar of ayudh

ASKER

Most of the suggestions given show how to get the screen widthXheight in javascript. Question is, how can I pass this information to the CF server?

The answer from hanj is the most promising so far, but it's not clear to me how this is achieved. Could you please elaborate hanj.

Ayudh Nagara
The solution it to "pass" the JS variable to CF.
for example in your login page you set 2 JS variables with width & height and then you could redirect to the mainlogin page and pass this variables for example:

------------------------------------------------------------
--login.cfm--
<script language="JavaScript">
var w = screen.width;
var h = screen.height;
<!--- redirect and pass width & height in the URL --->
window.location = "mainlogin.cfm?w=" + w + "&h=" + h
</script>

--mainlogin.cfm--
<!--- set to CF variable --->
<cfset session.width = URL.w>
<cfset session.height = URL.h>

ASKER CERTIFIED SOLUTION
Avatar of KobiK
KobiK

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ooops, should be:

<p>Width:  #CFW#
<p>Height: #CFH#

:-)
I think this is even "more elegant":

--login.cfm--
<cfif IsDefined("w") and IsDefined("h")>
    <cfset CFW = w>
    <cfset CFH = h>
    <cfoutput>
    <p>Width:  #CFW#
    <p>Height: #CFH#
    </cfoutput>
    <!---
    <cfset session.width = URL.w>
    <cfset session.height = URL.h>
    --->
<cfelse>
    <script language="JavaScript">
        document.write('<form name="MainForm" method="post" action="<cfoutput>#CGI.SCRIPT_NAME#</cfoutput>">');
        document.write('<input type="hidden" name="w" value="' + + screen.width + '">');
        document.write('<input type="hidden" name="h" value="' + + screen.height + '">');
        document.write('</form>');
        document.MainForm.submit();
    </script>
</cfif>

Anyway, Glad i could help :)
Thanks. Problem is ... I don't have the opportunity to call / post ... to another windoe using javascript ... as I'm connecting / calling / loading all pages using coldfusion.
Damn. I'm just not getting this.

Thanks anyway.