Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Screen Resolution and Typecasting

    I have created my own image resize function i will be using too, well, resize images placed inside div's based on the resolution of ones monitor. The only way i have found to grab the resolution is too use javascript screen.width ect.

    The javascript method returns a string and i cannot manipulate that value at all, even after typecasting as it just sets to blank.

    Pretty much all im asking is it possible to convert the data taken from the javascript values and make them numerical so i can perform addition, subtraction or anything on them.

  • #2
    Regular Coder 2reikis's Avatar
    Join Date
    Nov 2005
    Location
    New Mexico, USA
    Posts
    174
    Thanks
    18
    Thanked 13 Times in 13 Posts

    Flip flop javascript variables into php

    You can have a javascript that grabs the screen width and height and constructs a "get" string from it, then reloads the page.

    PHP Code:
    <?php
    if (!isset($_GET['sWidth'])) {
    ?>
    <script>
    sWidth = window.innerWidth != null? window.innerWidth :
     document.documentElement && document.documentElement.clientWidth ?
     document.documentElement.clientWidth : document.body != null ?
     document.body.clientWidth : null;
    document.location.replace(document.URL+"?sWidth="+pageWidth());
    </script>
    <?php
    }
    else
    {
    ?>
    <p>Screen width = <?php echo $_GET['sWidth'?> </p>
    <?php
    }
    ?>
    You can also post the variables using hidden form fields.

    HTH

    2reikis

  • #3
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thankyou for your response, i decided i would like to get the actual Div size instead of screen size. This is working great as far as i can see. If you can see any problems please let me know.

    link: http://brods.devolvedguild.com/onetwotree

    The middle content Div is the one with the image resize function grabbing the div width from the URL and altering the image included.

    Thanks again

  • #4
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    I can see an overflow problem on firefox
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •