SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling a PHP file with Javascript.

    In the head of my document, my Javascript file is called
    Code:
    <script language="javascript" src="detect.js"></script>
    This detects the resolution and picks the corret CSS file.

    The problem is, later on in my program I want to grab the information on which resolution the user is using so I can include a PHP file.

    However when I do
    PHP Code:
     document.write(' <?php include("corners.php"); ');
    I don't get anything but when I look at the source I get

    Code:
     document.write(' ALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODEALOT OF CODE ');
    What do I do?
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]

  2. #2
    SitePoint Wizard davidjmedlock's Avatar
    Join Date
    Dec 2002
    Location
    Nashville, TN USA
    Posts
    1,688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Might have to use an IFrame... Or, if you want to do sort of a no-refresh links thing try this article:

    http://www.sitepoint.com/article/314

  3. #3
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, I don't think you fully understand what I want.

    When the page loads the javascript fetches the users screen resolution and picks the correct StyleSheet to be applied.

    Then I need to apply the round corners which also needs to know what the screen resolution is, but I need to have the code for my corners outside the <head></head> unlike my initial StyleSheets.

    So further downt he page I call me Javascript again and return the resolution and pick the right corner file according to that. But it's not working properly.
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]

  4. #4
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, typical of document.write()...instead of writing the code in the file into the web page, it just displays the code. I've run into this problem several times myself.

    What I suggest you do is try just using the PHP code. Just write the PHP code in there, forget enclosing any JavaScript around it (and remember the closing php tag, ?>). If that doesn't work, there's always server side includes. Let us know, though.

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2001
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a feeling you cant do that, as php is parsed first on the server side, then the javascript is parsed by the client..you cant go back to server side parsing after its complete.

    is there possibly another way it can be done?

  6. #6
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, there's always server side includes...

    <!--#include file="corners.txt" -->

    Even if your PHP file is given a .txt extension, it will still work. You may have to change your web page's file extensions to .shtml, but that depends on your hosting service. This is a pretty easy method of including a file into the web page, though.

  7. #7
    SitePoint Addict madproject.com's Avatar
    Join Date
    Jan 2003
    Location
    Ottawa, Canada
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well what I ended up doing is taking my three main CSS files for the three supported resolutions: (800*600/1024*768/1280*1024)

    In each one I wrote the code for the different corner positioning.

    Then I wrote the <span id="topright"><img></span> code in a file that I included(<?php include("corners.php" ); ?> ) in my main index.php file.

    So what happens is the user opens the page, the javascript checks his resolution, fetches the appropriate CSS file with <link rel="StyleSheet" href="index.css"> and then the corners.php loads with the specific specs of the css sheet.

    WALLA.
    Free Picture and Video Hosting
    [http://photocabin.com][http://madproject.com]


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
  •