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)?
All give it a look.
http://devex.allaire.com/developer/gallery/info.cfm?ID=CA347503-2830-11D4-AA9700508B94F380&method=Full
Rajesh from India
http://devex.allaire.com/developer/gallery/info.cfm?ID=CA347503-2830-11D4-AA9700508B94F380&method=Full
Rajesh from India
Rajech: where are u from in India.
I am also from india.......
jimmy
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"+scree n.height;}
if (window.screen.colorDepth != '')
{JC_color = "&ColorDepth="+window.scre en.colorDe pth;}
</script>
i hope this helps
hanj
<script language="javascript">
from = ''; JC_screen = ''; JC_color = '';
if (document.referrer != '')
{from = "from="+document.referrer;
if (screen.width != '')
{JC_screen = "&ScreenRes="+screen.width
if (window.screen.colorDepth != '')
{JC_color = "&ColorDepth="+window.scre
</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,Radi o,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("newWindo w=open('ma in.htm','n ew','toolb ar=no,heig ht='+high+ ',width='+ wide+',lef t=0,top=0, resize=no, alwaysonto p=yes,alwa ysraised=y es')",3000 )
}
//-->
</script>
</head>
<body background="image/backgrou nd.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">&nbs p; </ td><td>
<font color=blue size=7><center>W &nbs p;e & nbsp;l&nbs p; c& nbsp;  ;o &n bsp;m  ; e&n bsp; <br> T o <br> M u z &nb sp;i c&nb sp; a &nbs p; Pvt. Ltd.</center>< /font>
</td><td>
<img src="image/note5.gif"></td ></tr></ta ble>
<tr><td nowrap align=center>
<table border=0 cellspacing=0 cellpadding=0><tr><td>
<img src="image/note5.gif"></td ></tr></ta ble></td>< /tr>
</table></td></tr></table>
</body>
</html>
Bye:-)
don't mide for images Ha Ha
<html>
<head>
<title>MuzicaOnline</title
<meta keywords="Music,Music Shopping,Musical Instruments,Music System,Casstte,CD,DVD,Radi
<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("newWindo
}
//-->
</script>
</head>
<body background="image/backgrou
<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
<table border=0 cellspacing=0 cellpadding=0 width=100%>
<tr><td><img src="image/note5.gif">&nbs
<font color=blue size=7><center>W &nbs
</td><td>
<img src="image/note5.gif"></td
<tr><td nowrap align=center>
<table border=0 cellspacing=0 cellpadding=0><tr><td>
<img src="image/note5.gif"></td
</table></td></tr></table>
</body>
</html>
Bye:-)
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 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>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ooops, should be:
<p>Width: #CFW#
<p>Height: #CFH#
:-)
<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.SCR IPT_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 :)
--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.SCR
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.
Damn. I'm just not getting this.
Thanks anyway.
You can detect screen size using JavaScript or ASP. In ASP you can use the following script:
<%
Response.Write Request.ServerVariables("H
' other info you may like
' This header indicates the number of colors that the browser can display
Response.Write Request.ServerVariables("H
' This header indicates the type of machine being used to execute the browser.
Response.Write Request.ServerVariables("H
' This header indicates the operating system of the computer executing the browser.
Response.Write Request.ServerVariables("H
%>
but you shouldn't rely on these headers; they are supported oly by the Win '95 versions of IE.