Re: URGENT : How to Detect screen resolution in COLDFUSION?

407 views
Skip to first unread message

hofar...@houseoffusion.com

unread,
Dec 22, 2012, 6:53:26 AM12/22/12
to ColdFusion Technical Talk

This should work nicely, tried out earlier today in Safari, Firefox and Chrome. Storing available vars in session for use throughout the app. My use case is loading a different include file that consumes smaller jpg files for a slider for mobile devices:

<cfif Not IsDefined('session.screenwidth')>

<cflock scope="session" type="exclusive" timeout="30">
<cfset session.screenwidth = "<script>document.write(screen.width);</script>">
<cfset session.screenheight = "<script>document.write(screen.height);</script>">
<cfset session.availWidth = "<script>document.write(screen.availWidth);</script>">
<cfset session.availHeight = "<script>document.write(screen.availHeight);</script>">
<cfset session.colorDepth = "<script>document.write(screen.colorDepth);</script>">
<cfset session.pixelDepth = "<script>document.write(screen.pixelDepth);</script>">
</cflock>

</cfif>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353604

hofar...@houseoffusion.com

unread,
Dec 22, 2012, 7:15:30 AM12/22/12
to ColdFusion Technical Talk

Javascript is client side and will only run in the browser, you cannot run
it from the server inside cfml.

so
<cfset session.screenwidth = "<script>document.write(
screen.width);</script>">
will simply assign the text "<script>document.write(screen.width);</script>"
to session.screenwidth not the value your are expecting.

you need to run this script client side.
<script>document.write(screen.width);</script>

and then send the values back to the server, you could do this with ajax or
cookies.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353605

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 2:22:03 AM12/23/12
to ColdFusion Technical Talk

I am running this in a cfml page and it returns the screen resolution consistently.

I was surprised to see js scripts in cfset would capture the desired values in a cfml page.

Try it on your end, technically it shouldn't work but I believe the virtual concurrency between server and client call produce the desired result.

>Javascript is client side and will only run in the browser, you cannot run
>it from the server inside cfml.
>
>so
><cfset session.screenwidth = "<script>document.write(
>screen.width);</script>">
>will simply assign the text "<script>document.write(screen.width);</script>"
>to session.screenwidth not the value your are expecting.
>
>you need to run this script client side.
><script>document.write(screen.width);</script>
>
>and then send the values back to the server, you could do this with ajax or
>cookies.
>
>
>
>
>>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353619

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:00:33 AM12/23/12
to ColdFusion Technical Talk

Impossible that it works as you describe.

If anyone runs this code they will simple see a session variable with a
string of js text.

<cfset session.screenwidth =
"<script>document.write(>screen.width);</script>" />
<cfdump var="#session#" />

You would have to do it with ajax as suggested, or use js to set a form
variable.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353621

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:06:34 AM12/23/12
to ColdFusion Technical Talk

Have you actually tried it?

>Impossible that it works as you describe.
>
>If anyone runs this code they will simple see a session variable with a
>string of js text.
>
><cfset session.screenwidth =
>"<script>document.write(>screen.width);</script>" />
><cfdump var="#session#" />
>
>You would have to do it with ajax as suggested, or use js to set a form
>variable.
>
>
>
>>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353622

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:08:56 AM12/23/12
to ColdFusion Technical Talk

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:08:36 AM12/23/12
to ColdFusion Technical Talk

What is this "virtual concurrency between server and client call" stuff? I
think I missed that in the instruction manual.

Paul is correct, that output requires a DOM to run, CF is just seeing a
text string.

View source will also show you the output JavaScript.

It is possible to pass those screen variables back to CF's session using
client side script, just not the way that is being presented.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353624

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:13:04 AM12/23/12
to ColdFusion Technical Talk

We don't need too...

As Paul and the others have stated, that code sets a variable with the text
between the quotes. Now if this is working for you, then maybe you can
explain where you are overriding these variables using Ajax. Because as it
stands, the only thing you will see when you dump the session scope, is the
text and not what you claim.

So unless you have some JavaScript that is interacting with the server,
then what you describe does not happen the way you're trying to explain.

--
Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353625

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:24:54 AM12/23/12
to ColdFusion Technical Talk

Checkout this test page link:

http://exelstudio.com/screensizetest.cfm

Here's the code:

<cfset screenwidth = "<script>document.write(screen.width);</script>">
<cfset screenheight = "<script>document.write(screen.height);</script>">
<cfset availWidth = "<script>document.write(screen.availWidth);</script>">
<cfset availHeight = "<script>document.write(screen.availHeight);</script>">
<cfset colorDepth = "<script>document.write(screen.colorDepth);</script>">
<cfset pixelDepth = "<script>document.write(screen.pixelDepth);</script>">

<cflock scope="session" type="exclusive" timeout="59">
<cfset session.screenwidth = screenwidth />
<cfset session.screenheight = screenheight />
</cflock>

<cfoutput>
<div style="padding:15px;">
Screen dimensions: #Session.Screenwidth# width X #Session.Screenheight# height<br /><br />

Available browser width: #availWidth#<br />
Available browser height: #availHeight#<br />
Color depth: #colordepth#<br />
Pixel depth: #pixelDepth#
</div>
</cfoutput>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353626

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:31:01 AM12/23/12
to ColdFusion Technical Talk

Just view the source, it is the JavaScript strings being parsed by the
browser, CF has no Idea what the variables are.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353627

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:31:45 AM12/23/12
to ColdFusion Technical Talk

I agree technically it should not work as one side is client, the other server, but on my test page it does present the js result value instead of the text string. Cfdump shows text strings, but within cfoutput tags seems to work showing the js results. A fluke :)

I tried the form post option, but its less than ideal doing another page call. If any of you have an example how to ajax post those vars from client to server, it will be much appreciated.

>What is this "virtual concurrency between server and client call" stuff? I
>think I missed that in the instruction manual.
>
>Paul is correct, that output requires a DOM to run, CF is just seeing a
>text string.
>
>View source will also show you the output JavaScript.
>
>It is possible to pass those screen variables back to CF's session using
>client side script, just not the way that is being presented.
>
>
>
>
>>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353628

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:37:25 AM12/23/12
to ColdFusion Technical Talk

Dang, you're right, I didn't look at the source, just the page. Browser has it, cf doesn't. So ajax post is prob best solution, form post test works but not ideal.

>Just view the source, it is the JavaScript strings being parsed by the
>browser, CF has no Idea what the variables are.
>
>
>
>
>>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353629

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:38:22 AM12/23/12
to ColdFusion Technical Talk

No, it is NOT showing the js result value instead of the text string, nor
is this a fluke. CF is outputting the exact same string you set them to,
the DOM in the browser is parsing the JavaScript so you see the variables.

As I mentioned, if you view the source of the HTML you will see those
strings exactly the way you set them.



--
/Kevin Pepperman

"*Never memorize what you can look up in books*."
--Albert_Einstein


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353630

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:43:05 AM12/23/12
to ColdFusion Technical Talk

Agreed, I saw the results on the page but completely forgot to check the actual page source. Any idea on the best way to ajax post to cf in jquery?
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353631

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:43:12 AM12/23/12
to ColdFusion Technical Talk

Ok I see what you're doing now, the reason it works on the browser is that
your placing (Or technically speaking injection JS into the
Dom) JavaScript into the requested page. That means when it displays it
will run that JS, but for ColdFusion to actually know about this, you have
to get JavaScript to return the variables via Ajax.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353632

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:50:18 AM12/23/12
to ColdFusion Technical Talk

Its just the basics, but I am falling asleep.

myData= "width=" + screen.width+ "&height="+screen.height;
$.ajax({
type: "POST",
url: "ajax.cfc?method=myMethod",
data: myData,
success: function(){}
});
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353633

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 3:54:45 AM12/23/12
to ColdFusion Technical Talk

Yes, it runs and displays client side but useless for any responsive conditional logic until that info is sent to cf. Will figure out how to get the values in jquery and ajax post to cf.

I've been using Zurb Foundation as its really a quite pleasant grid for responsive layouts. You can apply mobile classes on the same page in a fairly intuitive manner. What I'm trying to accomplish is loading smaller jpgs for mobile devices - i.e. a diff cf template displaying a slide show with diff set of jpgs depending on the viewport. Media queries in css won't work in this case.

>Ok I see what you're doing now, the reason it works on the browser is that
>your placing (Or technically speaking injection JS into the
>Dom) JavaScript into the requested page. That means when it displays it
>will run that JS, but for ColdFusion to actually know about this, you have
>to get JavaScript to return the variables via Ajax.
>
>--
>Regards,
>Andrew Scott
>WebSite: http://www.andyscott.id.au/
>Google+: http://plus.google.com/113032480415921517411
>
>
>
>
>
>>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353634

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 4:33:46 AM12/23/12
to ColdFusion Technical Talk

Thanks for the example Kevin, trying it out right now.

>Its just the basics, but I am falling asleep.
>
>myData= "width=" + screen.width+ "&height="+screen.height;
>$.ajax({
>type: "POST",
>url: "ajax.cfc?method=myMethod",
>data: myData,
>success: function(){}
>});
>
>
>
>
>>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353635

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 6:35:09 AM12/23/12
to ColdFusion Technical Talk

Thanks guys for the jquery pointer, much appreciated. Got it working so the data is now in cfml via ajax. Page source got numbers vs string. Doh !!

http://exelstudio.com/test5.cfm

jquery ajax call:

<script type="text/javascript">
var theData= "screenWidth=" + screen.width+ "&screenHeight="+screen.height;

$.ajax({
type: "POST",
url: "ajax.cfc?method=myMethod",
data: theData,
datatype: "json",
success: function(){}
});
</script>

ajax.cfc file:

<cfcomponent>
<cffunction name="myMethod" returntype="struct" access="remote" returnformat="json">
<cfargument name="screenWidth" type="numeric" required="no">
<cfargument name="screenHeight" type="numeric" required="no">

<cflock scope="session" type="exclusive" timeout="30">
<cfset session.screensize = StructNew()>
<cfset session.screensize.width= #arguments.screenWidth# />
<cfset session.screensize.height= #arguments.screenHeight# />
</cflock>

<cfreturn session.screensize>
</cffunction>
</cfcomponent>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353638

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 7:27:50 AM12/23/12
to ColdFusion Technical Talk

Glad you worked it out.
One thing you should do is make sure a session variable exists before using
the session variables.
When I first loaded the page I received an error, after I refreshed the
error went away.
You should cfparam the variables to a default first, otherwise they wont be
set until after you call the ajax request.

The success: function(){} is used to call back the data from the ajax
request, you could use those to dynamically set a div to the variable
returned.

Error Occurred While Processing Request
Element SCREENSIZE.WIDTH is undefined in SESSION.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353640

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 8:16:59 PM12/23/12
to ColdFusion Technical Talk

>>When I first loaded the page I received an error, after I refreshed the
error went away.

This method won't work either, because the Ajax function will be executed after the output of the page is already on client side.
This is why you get an error at the first call. So you have to call the template two times so it can use the session variable.
Furthermore, I'm not sure the Ajax function will use the same session as the calling program.


A better way would be to use redirection. Example:
<CFIF NOT isDefined("session.screenWidth")>
<CFIF NOT isDefined("url.sh")>
<SCRIPT>
window.location.href += "?sw=" + screen.width + "&sh=" + screen.height
</SCRIPT>
<CFELSE>
<CFSET session.screenWidth = url.sw>
<CFSET session.screenheight = url.sh>
</CFIF>
</CFIF>
<CFDUMP var="#session#">

You could also work out a POST method version using a FORM to transmit the values and the submit() function to redirect.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353653

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 8:51:25 PM12/23/12
to ColdFusion Technical Talk

I put a refresh tag below the script within conditions. It works, but still not ideal. It seems there's no way to avoid the 2nd step either redirect or form post.

<cfif Not IsDefined('Session.Screensize.Width')>
<script type="text/javascript">
var theData= "screenWidth=" + screen.width+ "&screenHeight="+screen.height;

$.ajax({
type: "POST",
url: "/ajax.cfc?method=myMethod",
data: theData,
datatype: "json",
success: function(){}
});
</script>
<meta http-equiv=refresh content="0;URL=test5.cfm">
</cfif>

Test page is:

http://exelstudio.com/test5.cfm
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353655

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 9:48:51 PM12/23/12
to ColdFusion Technical Talk

Add code in your Application.cfc onSessionStart() method, that makes sure
the default session variables exist right when the session starts.

You can also test for the session in onRequestStart() ,and call the
onSessionStart()
method if they don't exist.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353659

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 11:04:49 PM12/23/12
to ColdFusion Technical Talk

>>It seems there's no way to avoid the 2nd step either redirect or form post.

The problem is not with using POST or GET, the problem is using Ajax.
Ajax is good for many things, but not for this one.
Just as you first attempt did, the Ajax call will be performed from client side, AFTER the templated is executed and the page read by the browser.
You cannot do it without executing two steps, but wit redirection, the first step to get the values from the client is invisible for the user.

Try my code, there are two steps, but you only see one.
You can make a POST version of the same idea if
1. you do not like the idea of having parameters visible in the url,
2. you have other parameters to pass to the template.

Try this code, same idea using a form for redirection:
<CFIF NOT isDefined("session.screenWidth")>
<CFIF NOT isDefined("form.screenWidth")>
<FORM NAME="redirectForm" METHOD="POST">
<INPUT TYPE="hidden" NAME="screenWidth" VALUE="">
<INPUT TYPE="hidden" NAME="screenHeight" VALUE="">
<!--- Add any other values here --->
</FORM>
<SCRIPT>
document.redirectForm.screenWidth.value = screen.width;
document.redirectForm.screenHeight.value = screen.height;
document.redirectForm.action = window.location.href;
document.redirectForm.submit();
</SCRIPT>
<CFELSE>
<CFSET session.screenWidth = form.screenWidth>
<CFSET session.screenheight = form.screenHeight>
</CFIF>
</CFIF>

<!--- perform the true task of the template here --->
<CFDUMP var="#session#">


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353661

hofar...@houseoffusion.com

unread,
Dec 23, 2012, 11:34:10 PM12/23/12
to ColdFusion Technical Talk

Claude and Kevin, you are gentlemen and scholars. It worked with virtually negligible delay in the redirect.

Its a workable solution for getting the screen vars and loading appropriate size jpg images on that basis for mobile. Thank you for your input.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353662

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 1:49:57 AM12/24/12
to ColdFusion Technical Talk

One thing you may want to consider is giving the user an option. Sometime the user doesn't want your mobile version even though they are mobile. I find sites all the time where I'm given a mobile website that doesn't work as well as the desktop version. Sometimes even when they give me the option of using the desktop version the first link I click throws me back into the mobile version. As a mobile user give me the option and follow my wishes as to how I want to use the site. If you want me to buy something from your site, the easiest way to push me to the competition is to force me into what you think is best.

Just my 2 cents as a mobile user.

Sent from my iPhone
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353663

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 2:00:03 AM12/24/12
to ColdFusion Technical Talk

Good point.

A simple unobtrusive way to do this is to provide a "Desktop Version"
link in the footer of the mobile version which resets the session vars
to desktop.

Putting a popup or interstitial screen is pretty annoying in my pov and
having a link in the footer is pretty common these days (for those sites
that offer it.)
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353664

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 3:49:56 AM12/24/12
to ColdFusion Technical Talk

What got you into using Javascript as opposed to
CSS3 Media Queries for Responsive web design?

Rick
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353665

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 5:10:00 AM12/24/12
to ColdFusion Technical Talk

But you cannot get these values ntil after he page loads as they come from
the dom, so using ajax is perfectly valid way to send dom data back to cf

Regards
Russ Michaels
www.michaels.me.uk
www.cfmldeveloper.com - Free CFML hosting for developers
www.cfsearch.com - CF search engine
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353666

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 5:28:46 AM12/24/12
to ColdFusion Technical Talk

The website is the desktop version which adjusts nicely in the Zurb Foundation grid framework for phones.

Only thing I'm doing is loading smaller size jpg images. Same proportion image, but smaller width hence smaller file size/faster download.

For tablets desktop version looks/works fine.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353668

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 5:37:37 AM12/24/12
to ColdFusion Technical Talk

I use css media queries for layout, or more recently Zurb Foundation or Twitter Bootstrap, the former is much more elegant/intuitive grid, but Bootstrap has sexier looking eye candy ref buttons.

However in this instance I need to load smaller set of jpgs for a slider viewed on a phone. jpg img paths are referenced from the db as the images uploaded/resized via a back office admin section.

I couldn't see how css media queries could conditionally control which images are being referenced by cf from the server db. Hence I needed the screensize values in cf session.

I guess the other approach would be to get the screensize from css, but its still going to require a redirect or form post to save the values in cf session.

> What got you into using Javascript as opposed to
> CSS3 Media Queries for Responsive web design?
>
> Rick

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353669

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 5:43:17 AM12/24/12
to ColdFusion Technical Talk

Good idea, all it requires is a reset of the screensize session vars from the option link in the footer.

My approach at the moment is coding responsive pages. Have any of you found a happy path to doing separate mobile versions other than phonegap/jquery mobile?
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353670

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 6:12:28 AM12/24/12
to ColdFusion Technical Talk

Actually I can respond to id's and classes based on screen size via css media queries but can't get the specific values to store in cf. Btw, here's an interesting site just on media queries, lets you try out tests:

http://cssmediaqueries.com/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353672

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 8:57:56 AM12/24/12
to ColdFusion Technical Talk

>>But you cannot get these values ntil after he page loads

The page loads but reloads immediately sending the values in the same time.
It is still a two steps process, but in this case, the first step is automatic and transparent to the user.

>>so using ajax is perfectly valid way to send dom data back to cf

No, Ajax looks like magic, but it is still a plain Javascript function so it executes on client side only when the page loads, thus too late for the server to correctly use the screen width and height.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353673

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 9:05:04 AM12/24/12
to ColdFusion Technical Talk

>>Its a workable solution for getting

Now, the trick I gave was only to deal with the specific problem as you defined it, but there would be an even better solution.
I suppose the user has to go through some other page before he gets images.
So why not simply transmit the screen size before with some Javascript, for instance in hidden input fields set in an onsubmit event?
Once you get the values, put them in the session scope and that's it.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353674

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 9:11:39 AM12/24/12
to ColdFusion Technical Talk

This is the point in ajax, to send.data.from client side to server side.
Its not magic, it works like an iframe.

Regards
Russ Michaels
www.michaels.me.uk
www.cfmldeveloper.com - Free CFML hosting for developers
www.cfsearch.com - CF search engine
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353675

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 9:20:07 AM12/24/12
to ColdFusion Technical Talk

>>This is the point in ajax, to send.data.from client side to server side.

May be, but the point is still that when Ajax does it, the page that needed the data is already at client side, so it is too late.
For sending data to the server, there is still good old FORMs.
Ajax is more useful to get extra data from the server from a page on client side, to make the page more dynamic.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353676

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 9:36:32 AM12/24/12
to ColdFusion Technical Talk

I think your still not understanding the power of AJAX.
You can use AJAX to completely build a page on the fly,

client send data to server
server sends data back to client
client renders page according to data it received back from server.

so it matters not that the page did not know the info when it first loaded.

Probably overkill for your situation anyway, as would have a high learning
curve for you to learn all this if you don't already know ajax, so the
redirect is probably the best solution.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353677

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 10:12:11 AM12/24/12
to ColdFusion Technical Talk

>>I think your still not understanding the power of AJAX.

I think you still don't understand the point that Ajax is simply not the best solurion in this instance.

>>You can use AJAX to completely build a page on the fly,

Yes, of course you can, but when you can do better and simpler not using Ajax, why use Ajax?

>>Probably overkill for your situation anyway, as would have a high learning
curve for you to learn all this if you don't already know ajax, so the
redirect is probably the best solution.

LOL, I've been developing Web application since 1995, started with CF 1.1, when Windows Explorer, DOM and Javascript didn't even exist.
I've been using XMLHttpRequest functions as soon as they were made available and far before they were peremptorily named "Ajax",
I designed and used my own "Ajax" tools far before jQuery was available and probably you even heard of it ;-)
So I'm quite able and competent to decide when Ajax is the best and when another technique would be better or simpler ;-)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353678

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 1:40:45 PM12/24/12
to ColdFusion Technical Talk

Regards
Russ Michaels
www.michaels.me.uk
www.cfmldeveloper.com - Free CFML hosting for developers
www.cfsearch.com - CF search engine
On Dec 24, 2012 3:12 PM, <> wrote:
>
>
> >>I think your still not understanding the power of AJAX.
>
> I think you still don't understand the point that Ajax is simply not the
best solurion in this instance.

Erm, isn't that what I just said in my last reply ?????

>
> >>You can use AJAX to completely build a page on the fly,
>
> Yes, of course you can, but when you can do better and simpler not using
Ajax, why use Ajax?
>
Again, isn't that what I said in my last reply.
Read below statement.

> >>Probably overkill for your situation anyway, as would have a high
learning
> curve for you to learn all this if you don't already know ajax, so the
> redirect is probably the best solution.
>
> LOL, I've been developing Web application since 1995, started with CF
1.1, when Windows Explorer, DOM and Javascript didn't even exist.
> I've been using XMLHttpRequest functions as soon as they were made
available and far before they were peremptorily named "Ajax",
> I designed and used my own "Ajax" tools far before jQuery was available
and probably you even heard of it ;-)
> So I'm quite able and competent to decide when Ajax is the best and when
another technique would be better or simpler ;-)
>
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353679

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 8:45:48 PM12/24/12
to ColdFusion Technical Talk

I wish that were an option, unfortunately this is for a fairly elaborate full width slider on the home page of the website. Its the first thing you see. Its like a regular slider with about 10 images, but goes full width on available screen space.

So unless we did a welcome page, that wouldn't be an option and welcome splash pages are kinda cheezy in 2012.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353680

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 8:50:18 PM12/24/12
to ColdFusion Technical Talk

Hi Russ, so if we:

1. Go by ajax to a server cfc via client,
2. Server cfc returns the vars back to client

Is there then a way to save the vars that came back to the client from the server cfc into cf session scope, all in the same single page call?
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353682

hofar...@houseoffusion.com

unread,
Dec 24, 2012, 8:56:38 PM12/24/12
to ColdFusion Technical Talk

Hi Claude, perhaps the only way to do it with ajax in a 1 step process is to send the screen size vars to the cfc, then based on the results from the cfc have js append something to the image source path so a different set of image files loads.

Btw, have you looked into Angular or Knockout, any preference on what tools you use nowadays for richer client side usability?
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353683

hofar...@houseoffusion.com

unread,
Dec 25, 2012, 10:25:35 AM12/25/12
to ColdFusion Technical Talk

>>Hi Claude, perhaps the only way to do it with ajax in a 1 step process is to send the screen size vars to the cfc, then based on the results from the cfc have js append something to the image source path so a different set of image files loads.

Probably, if you absolutely want to use Ajax, but IMO it is unnecessarily complicated.

>>Btw, have you looked into Angular or Knockout, any preference on what tools you use nowadays for richer client side usability?

I have hundreds of pages in an application I started to develop about 10 years ago, and I didn't wait until fancy libraries of funcrions were available, and appart a few exceptions, I developed my own functions.
The advantage is that they do 100% I need, and 0% I don't need.
And when I need something new, I can add it right away, not wait for a new version to come out.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353684

hofar...@houseoffusion.com

unread,
Dec 25, 2012, 10:30:29 AM12/25/12
to ColdFusion Technical Talk

>>Is there then a way to save the vars that came back to the client from the server cfc into cf session scope,

The best would be to save it while still on the server from the cfc.
But you must make sure the session Id is transmitted to the cfc, otherwise it will define a new session.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353685

hofar...@houseoffusion.com

unread,
Dec 25, 2012, 11:09:49 AM12/25/12
to ColdFusion Technical Talk

That's why the WURFL project is the best option, you can also scale the
layouts you use as well.


--
Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353686

hofar...@houseoffusion.com

unread,
Dec 26, 2012, 5:14:18 PM12/26/12
to ColdFusion Technical Talk

How about just straight javascript... detect the screen resolution
and document .write the source of the images based on the screen resolution


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353687

hofar...@houseoffusion.com

unread,
Dec 26, 2012, 6:17:09 PM12/26/12
to ColdFusion Technical Talk

Not sure if someone suggested it or not, but .net can access computer
info...I wonder if there is a .net object out there that can read that?
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353689

hofar...@houseoffusion.com

unread,
Dec 26, 2012, 11:00:48 PM12/26/12
to ColdFusion Technical Talk

This seems very off the topic of the subject of ColdFusion. Can you
guys perhaps take it off list?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353692

hofar...@houseoffusion.com

unread,
Dec 26, 2012, 11:04:57 PM12/26/12
to ColdFusion Technical Talk

I've received over 20 mails on this topic, since its creation. Is it that no one can provide an answer for it or what
------Original Message------
From: Phillip Vector
To: cf-...@houseoffusion.com
ReplyTo: cf-...@houseoffusion.com
Subject: Re: URGENT : How to Detect screen resolution in COLDFUSION?
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353693

hofar...@houseoffusion.com

unread,
Dec 26, 2012, 11:08:45 PM12/26/12
to ColdFusion Technical Talk

They already have. Now they are talking about .net and javascript.

Hence my point.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353694

hofar...@houseoffusion.com

unread,
Dec 27, 2012, 1:08:25 AM12/27/12
to ColdFusion Technical Talk

Accessing .net objects or using JavaScript with ColdFusion is hardly off
topic. Just answer the question or delete the emails. Quit bitching about
it. This used to be a very friendly forum....
On Dec 26, 2012 10:01 PM, "Phillip Vector" <vec...@mostdeadlygame.com>
wrote:
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353696

hofar...@houseoffusion.com

unread,
Dec 27, 2012, 1:16:10 AM12/27/12
to ColdFusion Technical Talk

It seems however that it went from talking about using Javascript with
Coldfusion to using Javascript by itself..
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353697

hofar...@houseoffusion.com

unread,
Dec 27, 2012, 6:46:30 AM12/27/12
to ColdFusion Technical Talk

You mean a javascript if/else condition to defined what gets loaded?
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353698

hofar...@houseoffusion.com

unread,
Dec 27, 2012, 11:52:27 AM12/27/12
to ColdFusion Technical Talk

>>It seems however that it went from talking about using Javascript with
Coldfusion to using Javascript by itself..

So what ? This forum is for CF users. Are you a CF user who does not use Javascript?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353700

hofar...@houseoffusion.com

unread,
Dec 27, 2012, 12:23:08 PM12/27/12
to ColdFusion Technical Talk

There are other lists for discussing Javascript. I also use C#. Should
I start discussing C# code in here?

It was a polite request. Apparently, not everyone feels the same way,
so I retract it. Sorry for suggesting that we discuss.. you know..
Coldfusion. :)
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353701

hofar...@houseoffusion.com

unread,
Dec 28, 2012, 11:53:19 AM12/28/12
to ColdFusion Technical Talk

If C# has a solution that CF cannot readily provide and pertains to
accessing it via CF...yes

-----Original Message-----
From: Phillip Vector [mailto:vec...@mostdeadlygame.com]
Sent: Thursday, December 27, 2012 11:23 AM
To: cf-talk
Subject: Re: URGENT : How to Detect screen resolution in COLDFUSION?


Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353708
Reply all
Reply to author
Forward
0 new messages