Associate
- Joined
- 11 Oct 2008
- Posts
- 268
Hey guys,
I am using this code to use javascript to send the browser window width to a php session variable.
it works fine on my pc, however, when I try it on my phone it returns a width value of 900, which is wrong.
If i add the javascript directly it returns a true value of 350.
I uploaded a demo: http://www.myprimaryweb.co.uk/checkWidth/
Does anyone have any ideas whats going on? Cheers
I am using this code to use javascript to send the browser window width to a php session variable.
PHP:
session_start();
$parentDir = basename(dirname($_SERVER['PHP_SELF']));;
if (!isset($_SESSION['screenWidth'])) {
echo '<script>window.location = "' . "/" . $parentDir . "/" . '?width="+window.innerWidth</script>';
if (isset($_REQUEST['width'])) {
$_SESSION['screenWidth'] = $_REQUEST['width'];
header("Location: " . "http://" . $_SERVER['HTTP_HOST'] . "/" . $parentDir);
}
}
it works fine on my pc, however, when I try it on my phone it returns a width value of 900, which is wrong.
If i add the javascript directly it returns a true value of 350.
Code:
<button onclick="myFunction()">Get Width</button>
<script>
function myFunction() {
alert(window.innerWidth);
}
</script>
I uploaded a demo: http://www.myprimaryweb.co.uk/checkWidth/
Does anyone have any ideas whats going on? Cheers