SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow using Javascript variables...?

    Is it possible to use Javascript variable as PHP variables?

    For instance:
    <script language="Javascript">

    var Swidth = (screen.width);
    var Sheight = (screen.height);
    </script>

    and then to transfer them to
    $Swidth and $Sheight

    any help is appreciated!

    Jazz

  2. #2
    SitePoint Zealot oodie's Avatar
    Join Date
    Jul 2000
    Location
    Misty Mountain
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think so because PHP file is parsed before it's displayed on a browser while JavaScript is executed on client's side. You can, however, do the other way around

  3. #3
    SitePoint Evangelist cyngon's Avatar
    Join Date
    Aug 2001
    Location
    Livonia, MI, USA
    Posts
    513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is impossible to access a JavaScript variable using PHP. As oodie said, PHP is parsed on the server side and JavaScript is parsed on the client side. This is what allows us to have PHP scripts that generate JavaScript on the fly.

    However, if you have a PHP variable you would like to use in a JS on the page, you can do:

    PHP Code:
    <script language="Javascript">
    var Blah = <?php echo $blah?>;
    </script>

  4. #4
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also use javascript to alter your links so that they indicate the resolution so the next page... perhaps with an onclick script that would post those variables for the next page.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  5. #5
    SitePoint Evangelist cyngon's Avatar
    Join Date
    Aug 2001
    Location
    Livonia, MI, USA
    Posts
    513
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great idea, samsm.

    You could set it up so that the index page uses PHP to check if there is a cookie or session with the resolution. If there is no cookie or session set, the PHP could output a Javascript onto the page that forward the user back to the page they are on but with the resolution POSTed.

    The PHP script would then see the resolution in $_POST and set a cookie or session.

    Excellent out-of-the-box thinking. Unless there is a way to detect the resolution in PHP directly like we can do with browsers, this seems like a good solution.


Bookmarks

Posting Permissions

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