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
    New Coder
    Join Date
    Nov 2002
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.write and php

    //start newbie javascript question

    I'm trying to change my page layout depending on a user's screen resolution via javascript. If a user is 1024x768, I want a script that scrolls aross the top of the page to apear. If they don't meet the requirements, I don't want the script to appear.

    I figured I could use the screen.width to help me determine what the user's screen size was and then display the file imported via php. Unfortunatly it's not working and I receive a "parse error, unexpected T_CONSTANT_ENCAPSED_STRING " message. I've got different style sheets being used depending on resolution but I can't get this script to work:

    Code:
    <script type="text/javascript">
    <!-- 
        if ((screen.width >= 1024)){
            document.write('<div id="top">');
            document.write('<?php');
            document.write('include \'cloud_scroll.php\';');
            document.write('?>');
            document.write('</div>');
        }
    -->
    </script>
    If I add an escape character before the "?" ('<\?php') ) ,that gets rid of the parse error but the php portion of it doesn't work and the cloud_scroll.php file isn't included.

    Is the problem with the way I'm using document.write?

    // end newbie quesiton


    - C

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think that it can't work the way you want, as php is a server side language and you can't call it from javascript, that it's a client side language (that is, executed by the browser)
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #3
    New Coder
    Join Date
    Nov 2002
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That makes sense as to why it's not working then

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You might want to use an iframe for this...if the resolution test is passed, document.write the HTML for the iframe (embed the script in the <body>) which will allow you to download the PHP script into the iframe for display. As noted, a PHP include is meaningless on the client.

    Careful:

    }
    //-->
    </script>


  •  

    Posting Permissions

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