0
votes

My scenario is get the window height using javascript and have to pass the value to the coldfusion variable and set the value to the vlc player in cfm page.

$(window).height()

I m well aware of the ways how client side variable can be sent to server side like:

  1. Form submit
  2. Ajax

But if apply anyone from above i have to pass all the page default variable along with height but i don't want to send other variables, now my logic of getting height is in between one of the Cfincludes.

The page which i m working is one of the many includes so please provide some ideas.

case:

A.cfm

var javaScritheight = 1200;

B.cfm

<cfinclude template ="B.cfm?width="100%"&height=#javaScritheight#">
<cfparams name="width" default="240">
<cfparams name="height" default="360">



<video id="player" width="#width#" height="#height#">URL</video>

I should pass the javascript variable to another coldfusion page via cfinclude. Is it possible or am i misunderstanding the coldfusion functionalities? please share your thoughts.

1
You have to use one of those two methods to pass a client side value to CF. No way around it. For anyone to offer more specific advice, you would need to post a small, self-contained, repro case. See How to create a Minimal, Complete, and Verifiable example - Leigh
If this page is a target of a form or anchor tag, maybe you can get the information from the previous page. - Dan Bracuk
Without more detail, a third option might be to pass the height as a url parameter to the .cfm page. - snackboy
pass the javascript variable to another coldfusion page via cfinclude Javascript variables cannot be used in CFML code. Javascript code runs on the client - long after any CFML code has finished executing. Therefore you must submit two http requests. - Leigh

1 Answers

0
votes

I have done this before, to set a width in cfgrid. Here is that example. So you'll just have to replace Width with Height.

1) On some page, in my case when the user logs into the CMS, set a cookie.

<script type="text/javascript">
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else var expires = "";
    document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}
$(document).ready(function(){
    createCookie("bodyWidth", $(document).width()-20, 14);
});
</script>

2) On page load (onRequestStart) look for the cookie, if we don't already know the width. Also set a default in case of some javascript problem.

<!--- GRID WIDTHS --->
<cfif not isDefined("session.bodyWidth")>
    <cfif isDefined("cookie.bodyWidth")>
        <cfset session.bodyWidth = cookie.bodyWidth>
    <cfelse>
        <cfset session.bodyWidth = 1067>
    </cfif>
</cfif>

3) Later just use that session variable in CF. No need to pass it into the include path name.

<cfoutput>#session.bodyWidth#</cfoutput>

Just a note here. Step 2 might be enhanced such that if the user changes their window size the session var gets updated.