如何判断用户端浏览器的分辨率?

hlddn 2003-12-28 10:16:15
问题如上。
...全文
84 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
thunderx 2003-12-29
  • 打赏
  • 举报
回复
It's too late and I'm going to bed!See you tomorrow !
thunderx 2003-12-29
  • 打赏
  • 举报
回复
Sorry I's late because I have a examination tomorrow!ft~~~,just try this~!
<?php
if (isset($_GET['width']) AND isset($_GET['height'])) {
// output the geometry variables
echo "Screen width is: ". $_GET['width'] ."<br />\n";
echo "Screen height is: ". $_GET['height'] ."<br />\n";
} else {
// pass the geometry variables
// (preserve the original query string
// -- post variables will need to handled differently)

echo "<script language=\"javascript\">\n";
echo " location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
. "&width=\" + screen.width + \"&height=\" + screen.height;\n";
echo "</script>\n";
exit();
}
?>
hope1983 2003-12-29
  • 打赏
  • 举报
回复
汗,原来是这样.
PHP在服务器端运行,JS在客户端运行,PHP的值可以让JS调用,JS的值除了用表单提交,怎么可能让PHP调用呢。
jbroom 2003-12-29
  • 打赏
  • 举报
回复
是的,想在网页上显示,只要可以作为变量用就可以了,我找这方面的东东找了好长时间了,也没人给我说

我有一个想法不知道行不行

就是用java测到ie分辨率,然后让这个网页自动转到一个网址,如:http://...../xxx.php?w=800&h=600

能实现吗?我对java不是很明白
jbroom 2003-12-29
  • 打赏
  • 举报
回复
你这样作,那个分辨率还是没有赋给应该的变量,你的这段代码和没有写一样,直接这样就也是一样的
<script language=javascript>
alert ('分辨率为 ' + screen.width + '×' + screen.height );
</script>

不用写那段PHP程序了,我感觉只能通java来实现,在客户端生成一个页后java测到数值,赋给text,然后客户端再提交回服务,也许这样可以实现
hope1983 2003-12-29
  • 打赏
  • 举报
回复
提示窗的就是分辨率
原来你是想在网叶上显示?
jbroom 2003-12-29
  • 打赏
  • 举报
回复
楼上

不行,只能弹出来一个提示窗,但是在网页并没有输出$width
hope1983 2003-12-29
  • 打赏
  • 举报
回复
这是弹出判断用户端浏览器的分辨率的变量$width
给个例子而已,你可以按实际应用
<?php
function hope1983()
{
echo "<script language=javascript>
alert ('分辨率为 ' + screen.width + '×' + screen.height );
</script>
";
}
$width=hope1983();
echo $width; //输出

?>
mikespook 2003-12-29
  • 打赏
  • 举报
回复
if(empty($_GET["width"])||empty($_GET["height"]))
{
echo <<<EOT
<script language="javascript">
echo "<script language=\"JavaScript\">
w = window.screen.width;
h = window.screen.height;
self.location=self.location+\"?width=\"+w+\"&height=\"+h;</script>";
</script>
EOT;
exit();
}
ar7_top 2003-12-29
  • 打赏
  • 举报
回复
<script language=javascript>
document.write(window.screen.width);
document.write(window.screen.height);
</script>
hlddn 2003-12-29
  • 打赏
  • 举报
回复
thunderx(平生一笑) 的方法很有用,但是用这种方法,URL后面老是加着一个
?width=***&height=***也是怪怪的。
hlddn 2003-12-28
  • 打赏
  • 举报
回复
那如何能把用js得到的分辨率赋值给一个php变量呢?将screen.width得值赋给$width.
hope1983 2003-12-28
  • 打赏
  • 举报
回复
echo "<script language=javascript>
alert ('分辨率为 ' + screen.width + '×' + screen.height );
</script>
";
孟子E章 2003-12-28
  • 打赏
  • 举报
回复
window.screen.width
window.screen.height

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧