JavasScript variable to Coldfusion

Discussion in 'Programming' started by Sushi_Master, May 28, 2009.

  1. #1
    I need to pass the screen height and width to coldfusion variables, so I can output the value in a link.

    e.g.

    
    <a href="http://mysite/myfolder/?keepThis=true&amp;TB_iframe=true&amp;height=<cfoutput>#height#</cfoutput>&amp;width=<cfoutput>#width#</cfoutput>" class="smoothbox" title="mypage">mypage</a>
    
    Code (markup):
    My problem is how can I get javascript screen.height stored as the coldfusion variable #height# ?

    Thanks in advance for your advice.
     
    Sushi_Master, May 28, 2009 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Javascript runs _after_ all ColdFusion code is already finished. So you cannot do this on the same page/request. You need to use separate pages (or ajax).

    The first page would grab the screen height using javascript, and pass that value to the second page, in either a form field or as a url variable.

    Page 1:
    <script>
    ...
    document.href = "http://yoursite.com/page2.cfm?height"+ jsHeightVariable;
    </script>

    Then the second page will have access to #height# as a either a URL or FORM variable, depending on which method you used on page 1:

    Page 2:
    #url.height# ... or
    #form.height#
     
    cfStarlight, May 28, 2009 IP
  3. xheartonfire43x

    xheartonfire43x Guest

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The only problem with doing what cfstarlight says is that if your index page is just a script that get the screen size and pushes it to another page your SEO is going to go way down. Search engines do not like re-routing like that on the Home Page.
     
    xheartonfire43x, Jun 22, 2009 IP
  4. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Who asked about SEO? The question was about javascript and the answer is correct. It cannot be done in a single request.
     
    cfStarlight, Jun 23, 2009 IP