Page 1 of 1

help me ...please

Posted: Thu Jan 08, 2004 2:54 pm
by basdog22
I have a code like this:

Code: Select all

<?php
if($ie=="ie")
{  //I end the php to do some javascript
 ?>
<script type="javascript">
if (screen.width==800 || screen.height==600)
{
<?php $ie="small"; ?> 
}
</script>
 <?php
}

....
....

?>
what am i doing wrong???

if i am right then if the javascript IF statement is wrong then the $ie will never be "small". But when i try it , it is always "small"

i tried:

document.write and more but it just want work

Posted: Thu Jan 08, 2004 3:18 pm
by Gen-ik
You can't mix PHP with JavaScript like that. PHP runs on the server before the page is sent to the browser. JavaScript runs once the page has been sent to the browser.

If you want to get a variable from JS to PHP you will need to send it via GET (as part of a url) or POST (as part of a form).

Posted: Thu Jan 08, 2004 3:25 pm
by basdog22
oops :oops: :oops: :oops: :oops: :oops: :oops: :oops:


Maybe there is another way...

What i want is :

see if the user has: 800x600 resolution and link another stylesheet for him.

If the user has more than 800x600 then link the default stylesheet..

Is there a way to do that???

Posted: Thu Jan 08, 2004 3:43 pm
by Gen-ik
This should work...

Code: Select all

<head>
<script type="text/javascript">

var file = screen.width==800 && screen.height==600 ? "small" : "default";

document.write('<link href="'+file+'.css" type="text/css" rel="stylesheet" />\r\n');

</script>
</head>
I tend to use a similar thing now and again to change the background-color/style of a website depending on the time of day (or night).

Posted: Thu Jan 08, 2004 3:53 pm
by basdog22
this is ok but...

i already coded a css switcher in php and it depends on which browser the user uses...So i must either recode the switcher in javascript or find a shorter way...

Thanks Gen-ik :wink:

Posted: Thu Jan 08, 2004 4:07 pm
by Gen-ik
I would always normally suggest to people to use PHP, but for this job I would recommened JS. The main reason being you won't have to bounce people around to different pages just to sort out the CSS.

Here's my JS I use for basic browser/OS detection...

Code: Select all

var o = new Object();

o.u =  navigator.userAgent.toLowerCase();
o.a =  navigator.appName.toLowerCase();
o.av = navigator.appVersion;

o.aol   = o.u.indexOf('aol')!=-1 ? true : false;
o.opera = o.u.indexOf('opera')!=-1 ? true : false;
o.lynx  = o.u.indexOf('lynx')!=-1 ? true : false;
o.ns    = !o.opera && o.a.indexOf('netscape')!=-1 ? true : false;
o.gecko = o.u.indexOf('gecko')!=-1 ? true : false;
o.ie    = !o.opera && o.u.indexOf('msie')!=-1 ? true : false;

o.unix = o.u.indexOf("x11")!=-1 || o.u.indexOf("sunos")!=-1 || o.u.indexOf("linux")!=-1 ? true:false;
o.mac  = o.u.indexOf("mac")!=-1 || o.u.indexOf("ppc")!=-1 ? true:false;
o.win  = o.u.indexOf('win')!=-1 ? true:false;
To check for IE and WIN for example just use something like if(o.ie && o.win){ do something }

Posted: Thu Jan 08, 2004 4:32 pm
by basdog22
great :D :D :D :D

BTW what is going on with your avatar????? :?: :?: :?: :?: :?: 8O :P :P :P

Posted: Fri Jan 09, 2004 8:10 am
by Gen-ik
basdog22 wrote:great :D :D :D :D

BTW what is going on with your avatar????? :?: :?: :?: :?: :?: 8O :P :P :P
Ha. I've made myself one of those (random) avatars ;)

Posted: Fri Jan 09, 2004 8:34 am
by Nay
Gen-ik wrote:
Ha. I've made myself one of those (random) avatars ;)
One of those eh? ;)

-Nay