QUOTE(CodeBasic @ Apr 30 2009, 11:22 AM)
hi..i wan to ask how to use PHP to check the browser window size ? if let say, my code:
<?
$myWidth = '<script> document.write(window.innerWidth); </script>';
echo $myWidth;
if ($myWidth < 1008) { //when i resize the browser window to 1024x768px, the echo $myWidth is 1008
$setWidth = 550;
echo '<div id="Panorama" style="width:'.$setWidth.'px; height:130px;overflow:hidden; background-color: transparent; margin-top:5; padding: 20px; margin-left: 0px;">';
} else { //when i resize the browser window to 1280x800px, the echo $myWidth is 1264
$setWidth = 750;
echo '<div id="Panorama" style="width:'.$setWidth.'px; height:130px;overflow:hidden; background-color: transparent; margin-top:5; padding: 20px; margin-left: 0px;">';
}?>
My problem is : No matter how i resize the browser window size, it always go to if ($myWidth < 1008){}...i cant get the $setWidth correctly, anything wrong in my code?
<?
$myWidth = '<script> document.write(window.innerWidth); </script>';
echo $myWidth;
if ($myWidth < 1008) { //when i resize the browser window to 1024x768px, the echo $myWidth is 1008
$setWidth = 550;
echo '<div id="Panorama" style="width:'.$setWidth.'px; height:130px;overflow:hidden; background-color: transparent; margin-top:5; padding: 20px; margin-left: 0px;">';
} else { //when i resize the browser window to 1280x800px, the echo $myWidth is 1264
$setWidth = 750;
echo '<div id="Panorama" style="width:'.$setWidth.'px; height:130px;overflow:hidden; background-color: transparent; margin-top:5; padding: 20px; margin-left: 0px;">';
}?>
My problem is : No matter how i resize the browser window size, it always go to if ($myWidth < 1008){}...i cant get the $setWidth correctly, anything wrong in my code?
QUOTE(CodeBasic @ Apr 30 2009, 04:45 PM)
Your $myWidth is a string(which is '<script> document.write(window.innerWidth); </script>') which you cannot compare it with integer. If you want to get the window resolution, you need to do it in javascript then resize the "panorama" in javascript.EG:
CODE
<script type="text/javascript">
var wwidth = window.innerWidth;
var setwidth;
if(wwidth < 1008)
{
setwidth = 550;
}
else
{
setwidth = 750;
}
document.getElementById('panorama').style.width = setwidth;
</script>
<div id="Panorama" style="height:130px;overflow:hidden; background-color: transparent; margin-top:5; padding: 20px; margin-left: 0px;">
var wwidth = window.innerWidth;
var setwidth;
if(wwidth < 1008)
{
setwidth = 550;
}
else
{
setwidth = 750;
}
document.getElementById('panorama').style.width = setwidth;
</script>
<div id="Panorama" style="height:130px;overflow:hidden; background-color: transparent; margin-top:5; padding: 20px; margin-left: 0px;">
PLEASE TAKE NOTE THAT I NEVER TEST THIS SCRIPT, but it should work.
May 2 2009, 12:33 AM

Quote
0.0196sec
0.41
6 queries
GZIP Disabled