#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    4
    Rep Power
    0

    Question PHP and Javascript


    Hi,

    Can someone help me with this:

    I've a page called: index.php

    I want to add a variable 'w'with the screen width so I can use the variable 'w' for php purposes.

    Here's the code I use now:


    <?php
    if ( !isset($w) ) { ?>

    <SCRIPT language="JavaScript">
    <!--
    var w = screen.width;

    window.location.replace("<?php echo (basename($PHP_SELF) ?>?w=" + w );
    //-->
    </SCRIPT>


    This works fine when there all no other variables after index.php, but what if there's already an index.php?x=10

    How can I adjust the script so I get

    index.php?w=1024

    or

    index.php?x=10&w=1024

    when needed?

    Thanx,

    Marcel
  2. #2
  3. No Profile Picture
    PHP Coder
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Ontario
    Posts
    66
    Rep Power
    14
    <?php
    if (!isset($w) || !isset($h) ) {
    ?>

    <script language="JavaScript">
    <![CDATA[
    var w = screen.width;
    var h = screen.height;
    window.location.replace("<?php echo (basename($PHP_SELF) ?>?w="+w+"&h="+h);
    //-->
    </script>

    aside from the XHTML-compliant CDATA thing that I probably screwed up, that should work. It will give you the width ($w) and the height ($h).
    Click here and wait. It's a kewl effect, trust me.

IMN logo majestic logo threadwatch logo seochat tools logo