开发者

height of the window portview in a session variable

开发者 https://www.devze.com 2023-01-23 02:40 出处:网络
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?

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
0

精彩评论

暂无评论...
验证码 换一张
取 消