...

View Full Version : JavaScript/PHP



IKinsler
07-13-2002, 04:18 AM
I currently program my entire web site in PHP. However, recenty I needed to detect the screen size and subtract a certain amount from it, then create a table that wide. BUT, unfortunately it doesn't work.

Can someone please help me on how to detect a user's screen size with PHP?

chrisvmarle
07-13-2002, 09:55 AM
I think it can't be done using only PHP. As your subject says, you might need JavaScript.

PHP is executed on the server before any information of the user (like screen size) is sent to PHP.

Mzzl, Chris

Flamerule
07-13-2002, 11:09 AM
You should use relative (%) values rather than absolute :

For example : if you want the table to be half the size of the screen do :

<table width="50%">

firepages
07-14-2002, 04:53 AM
whilst you can not rely on anyone having javascript .. you can pass the width and height from javascript to PHP...



<script>
function have_script(){
<?if(!$_GET[width]){?>
location.href="<?=$_SERVER[PHP_SELF];?>?width="+screen.width+"&height="+screen.height;
<?}?>
}
</script>
<body onload="have_script()">
<?if($_GET[height]){
echo "$_GET[height] :: $_GET[width]";
}else{
echo "javascript not available";
}
?>

so that reloads the page with the $_GET[width] && $_GET[height] variables available to PHP, non-js browsers will just ignore it so you can not depend on the values being available.

sgwd
11-25-2005, 07:42 PM
How to call to a function in javascript sending a numerical parameter? This parameter will be used in php code inside javascript:

call the javascript function:
<A href='javascript:void(0)' onClick='ShowFAQ(25)'>text</A>

<script type="text/javascript">
function ShowFAQ(faqid){
window.document.labeltitlefaq.innerText='<?php echo($arrayFAQtitle[faqid])?>' ;
}
</script>

Thanks for your support

sgwd
11-25-2005, 07:43 PM
Forget to say that the previous code does not work.

Jeune
08-28-2006, 04:07 AM
Hello :( I would like to know how can I save in a php variable the result of a javascript function :confused: Thank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum