I don't know of a way to determine the state of JS (or cookies for that
matter) before you send your first ColdFusion page. Essentially you must
send something to the browser to do the check, then that something can
inform ColdFusion.
However you can do the check and let CF know before the NEXT page.
I use modified from my (now out of date) article on getting client
resolution data via script and an image - but this also gives you JS
information.
The basic code for the client follows.
If JavaScript is enabled this code determines which version is available and
then, using that determines some metrics for the browser/screen (resolution,
color depth and window sizes).
Note that if JavaScript ISN'T enabled you'll trigger the "noscript" tag at
the bottom.
<!--- Output the GetRes Code --->
<script language="Javascript" type="text/javascript">var JSVersion =
1.0</script>
<script language="Javascript1.1" type="text/javascript">JSVersion =
1.1</script>
<script language="Javascript1.2" type="text/javascript">JSVersion =
1.2</script>
<script language="Javascript1.3" type="text/javascript">JSVersion =
1.3</script>
<script language="Javascript1.4" type="text/javascript">JSVersion =
1.4</script>
<script language="Javascript1.5" type="text/javascript">JSVersion =
1.5</script>
<script language="Javascript" type="text/javascript"><!--
// Default all Values to Zero
ColorDepth = 0;
ResHeight = 0;
ResWidth = 0;
ResAvailHeight = 0;
ResAvailWidth = 0;
ResBrowserHeight = 0;
ResBrowserWidth = 0;
// Get the basic values
if (JSVersion > 1.1) {
ColorDepth = screen.colorDepth;
ResHeight = screen.height;
ResWidth = screen.width;
ResAvailHeight = screen.availHeight;
ResAvailWidth = screen.availWidth;
};
// Try to get the Browser Window info
// If the innerwidth property is set then try to use that -
supported by Netscape and several other browsers
if( typeof( window.innerWidth ) == 'number' ) {
ResBrowserWidth = window.innerWidth;
ResBrowserHeight = window.innerHeight;
// The following is only supported by IE 6 in some cases.
} else if( ( typeof( document.documentElement.clientWidth ) ==
'number' ) && ( document.documentElement.clientWidth > 0 ) ) {
ResBrowserWidth = document.documentElement.clientWidth;
ResBrowserHeight = document.documentElement.clientHeight;
// Finally test if we're IE and use the IE specific values
} else if( document.body && ( document.body.clientWidth ||
document.body.clientHeight ) ) {
ResBrowserWidth = document.body.clientWidth;
ResBrowserHeight = document.body.clientHeight;
};
// Create the call to the image
document.write("<img src='FauxGIF.cfm?ScreenData=JS" + JSVersion +
"," + ColorDepth + "," + ResHeight + "," + ResWidth + "," + ResAvailHeight +
"," + ResAvailWidth + "," + ResBrowserHeight + "," + ResBrowserWidth + "'
width='1' height='1' alt='' border='0'>");
//-->
</script>
<noscript><img name="HeartBeat"
src="FauxGIF.cfm?ScreenData=NoJS,0,0,0,0,0,0,0" width="1" height="1" alt=""
border="0"></noscript>
You can run the above code on an entry page or even on every page in the
site - but I recommend doing the latter only if you're checking first. (For
example your CF application should keep track of the fact it tried already
and not output the code every time - just on the first page visited).
You have to change the img links in the code above to point to the right
spot. The "FauxGif.cfm" file is a CF file that accepts the URL parameters
you're passing it and returns a single pixel, transparent GIF image.
Here's a simplified "FauxGif.cfm" file. This file assumes that session
management is enabled and will dump all of your collected agent information
into a "Session.AgentInfo" structure.
You can then examine "Session.AgentInfo.JSVersion" to get the version of
JavaScript supported (or "NoJS" if it's disabled).
<!--- Append the Data to the File --->
<cfif IsDefined("URL.ScreenData")>
<cfset Session.AgentInfo = StructNew() />
<!--- Add the res information to the UserData Store --->
<cfset Session.AgentInfo.JSVersion = ListGetAt(URL.ScreenData, 1) />
<cfset Session.AgentInfo.ColorDepth = ListGetAt(URL.ScreenData, 2)
/>
<cfset Session.AgentInfo.ResHeight = ListGetAt(URL.ScreenData, 3) />
<cfset Session.AgentInfo.ResWidth = ListGetAt(URL.ScreenData, 4) />
<cfset Session.AgentInfo.ResAvailHeight = ListGetAt(URL.ScreenData,
5) />
<cfset Session.AgentInfo.ResAvailWidth = ListGetAt(URL.ScreenData,
6) />
<cfset Session.AgentInfo.ResBrowserHeight =
ListGetAt(URL.ScreenData, 7) />
<cfset Session.AgentInfo.ResBrowserWidth = ListGetAt(URL.ScreenData,
8) />
</cfif>
<!--- Write out the real GIF --->
<cfcontent type="image/GIF" file="d:/WebRoot/Tiny.gif" />
You have to change the path in CFCONTENT to point to an actually single
pixel gif (or any graphic you want, really - but if you change the
dimensions remember to also change the image tag from the first block of
code).
Once all this is done you're application will have the information you need
ready for the next page build.
There are problems with this technique however. It won't work with images
disabled, for example.
Hope this helps,
Jim Davis
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:207339
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54