SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
May 8, 2003, 11:03 #1
- 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>
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"); ');
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 ');
-
May 8, 2003, 11:18 #2
- 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/314WishList.com - Universal Gift Registry
KodeFusion.com | AgentOvation | Web Dev Sucess Blog | Net Realty
-
May 8, 2003, 11:29 #3
- 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.
-
May 8, 2003, 12:02 #4
- 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.
-
May 8, 2003, 12:03 #5
- 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?
-
May 8, 2003, 12:10 #6
- 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.
-
May 8, 2003, 12:29 #7
- 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.
Bookmarks