从JavaScript到PHP的数据传输 [英] Data transfer from JavaScript to PHP
问题描述
我如何获得浏览器的高度和宽度到php?像从JavaScript到PHP的数据传输?
使用 innerHeight
和 InnerWidth
,我想。
How can i get the browser's height and width to php? Like a data transfer from javascript to php?
With using innerHeight
and InnerWidth
, i think.
(我只是需要向用户展示小图片,如果他的屏幕尺寸较小,如果大一些,并且没有关于屏幕尺寸的数据,我不能这样做)
(I just need to show user small picture if he has small screensize and big if big and without a data about screensize i cant do it)
我有像这样:
I have like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/slideshow.css" type="text/css" />
<script>
document.write('script.php?screen=' + screen.width + 'x' + screen.height');
</script>
</head>
<body>
<?php $lol=$_GET['screen'];
<?php echo "SIZE : $lol" ?>
</body>
</html>
它不起作用。我做错了什么?
And it doesnt works. What i'm doing wrong?
推荐答案
您必须从JavaScript调用PHP脚本进行AJAX调用。该PHP脚本将保存当前会话中的屏幕分辨率(您需要为此使用会话)。稍后请求的PHP脚本可以访问由JavaScript代码段传递的屏幕分辨率。
You would have to make an AJAX call from JavaScript to a PHP script. That PHP script would save the screen resolution in the current session (you'll need to use sessions for this). A PHP script requested at a later point could then access the screen resolution as passed by the JavaScript snippet.
这篇关于从JavaScript到PHP的数据传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!