height of the window portview in a session variable
I would like to save the height of the window's portview (browser) in a session variab开发者_开发技巧le. Is that possible and how is it done?
var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
In a PHP session variable? You could make an AJAX call to a PHP script that would store the incoming variable in the PHP session.
Javascript
var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
jQuery.post('URL_TO_PHP_SCRIPT_HERE', {height: viewportHeight});
PHP
$_SESSION['viewportHeight'] = $_POST['height'];
Be sure to sanitize the incoming $_POST data. Maybe use intval()
on $_POST['height']
.
Here are some suggestions:
- Pass your variable in query string
- Pass it via hidden field
- Use cookies instead.
- Pass your variable via ajax and store in php session
精彩评论