Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8210075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:56:56+00:00 2026-06-07T09:56:56+00:00

I am using the following code to fetch the screen height: <CFSET rheight =

  • 0

I am using the following code to fetch the screen height:

<CFSET rheight = "<script>document.write(screen.height);</script>">

The value of rheight comes out as 768, which is correct.

But when I do this :-:

<CFSET sheight = rheight / 4>

I get the following error:

The value document.write(screen.height); cannot be converted to a number.

The idea is to get the screen height in number format without reloading the page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:56:59+00:00Added an answer on June 7, 2026 at 9:56 am

    There are a number of ways this can be done:

    No AJAX

    Without using any AJAX requests, you could achieve the desired result using the following code (just tested in CF 9.0.2 and CF10):

    <cfset rheight = "
        <script type='text/javascript' 
            src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'>
        </script>
        <script>
        $(document).ready(function() { 
            $('input.screenHeight').val(screen.height);
            alert($('input.screenHeight').val() / 4);
        })
        </script>">
    
    <cfhtmlhead text="#rheight#" />
    
    <input type="text" class="screenHeight" />
    

    In this example, we are creating a string variable that contains a reference to the jQuery library AND your custom code to obtain the screen height.

    We’ll set the height as the value of a text input box. We can then pull out the value and convert it into the number. You could convert the value before it was placed into the input box, like so:

    $('input.screenHeight').val(screen.height/4);
    

    The string variable is added to the head of the document using the cfhtmlhead tag:

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ae9.html

    This would only work for the original page view. If you needed to obtain the dimensions after changes in the page or responsive design layout changes, you would need to run an AJAX request to bring back the screen dimensions.

    No CFML

    Of course, you don’t need to use ColdFusion at all. You could get the same number conversion from JavaScript alone:

    <script type='text/javascript'     
        src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'>
    </script>
    <script type='text/javascript'>
        var getScreenHeight = function() {
            return screen.height;
        }
    
        $(document).ready(function() { 
        var screenheight = getScreenHeight();
        console.log(screenheight/4);
        })
    </script>
    

    However, it looks like you need to be able to persist the value from the screen height response in ColdFusion, like so:

    With AJAX AND CFML

    Amending the above JavaScript example, we can create an AJAX request to post the screen height value to a new .cfm page:

    <script type='text/javascript'>
    var getScreenHeight = function() {
        return screen.height;
    }
    
    $(document).ready(function() { 
        var screenheight = getScreenHeight();
    
    $.get("screensize.cfm",
        { screenheight: screenheight },
        function(data) {
            console.log('screen height has been set in the session scope: ' + data);
        }
    )
    })
    </script>
    

    At it’s most basic, the screensize.cfm could include the following:

    <cfsetting showdebugoutput="false" />
    <cfparam name="URL.screenheight" type="numeric" default="800" />
    
    <cfset session.screenheight = URL.screenheight />
    
    <cfoutput>#session.screenheight#</cfoutput>
    

    (this does not include any validation or failure captures that you may need to include)

    Assuming your application has session management enabled, this will place the value you send into the SESSION scope for use throughout the application.

    One thing to remember here is that the value in the SESSION scope will not be available to the original calling page (the one that made the AJAX request) until it has been refreshed.

    I hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to fetch data out of my Core Data graph:
I am using the following code to fetch html source website. private string Extract_Source(string
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
I'm using the following code to fetch something from mongo: class BlockingMongoFetcher include MongoConfig
I fetch record from database using following code. for (LocWiseProfileBeans cn : LocWiseProfile) {
I am using the following code to send out emails, the problem I am
I am using following code to fetch images using database with php. while($row =
I am using the following code to fetch the contents of a web page
Im using the following code to fetch image from a file,create an image list
I am using the following code to fetch all mails since 1 day less

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.