Forum Moderators: coopster
I'm defining a variable and assigning the platform to it in javascript.
var OS = navigator.platform
then I want to call my stylesheet using PHP include. Like this:
if (OS=="MacPPC")
{
<?php include("/stylesheet1.css");?>;
}
However this statement does not work at all. Any suggestions? Or is there a way to call a file from Javascript?
You're going about it a little backwards ... :)
PHP is rendered at the server, and then the page is delivered to the client (browser) where Javascript can do it's thing.
You need to do one of two things:
1) Use Javascript for the whole thing, or
2) Use PHP for the whole thing
1)
if (OS=="MacPPC") { document.write("<style type='text/css' href='/stylesheet1.css' />"); } 2) To use PHP for OS detection, you will need to either parse out the OS reference from the
$_SERVER['HTTP_USER_AGENT'] string or incorporate something like the PEAR Net_UserAgent_Detect [pear.php.net] class, which is based on the Javascript functions used by the above scriptlet. [edited by: StupidScript at 6:40 pm (utc) on July 11, 2006]