在PHP中获取屏幕宽度? [英] get screen width in php?

查看:75
本文介绍了在PHP中获取屏幕宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在php中获取屏幕宽度? (可能是PC,手机.)

how to get screen width in php? (may be pc, mobile phone..)

推荐答案

PHP本身仅在服务器端起作用,对客户端系统一无所知客户端在某些HTTP请求中发送给服务器端的信息.也就是说,使用JavaScript 收集当前客户端环境的必需信息(例如窗口大小)是不可避免的.

我认为需要内部窗口宽度,因为这是确定内容设计的客户端宽度.

现在,JavaScript通过属性window.innerWidth获取有关窗口宽度的信息.这是一个标准属性,请参见 http://www.w3schools.com/jsref/obj_window.asp [ ^ ],但是有多种不兼容之处,例如IE中,例如参见 http://www.javascriptkit.com/javatutors/static2.shtml [ http://www.javascripter.net/faq/browserw.htm [ ^ ].

为了避免不兼容,我将使用jQuery
PHP itself works only on server side and does not know anything about client system except information sent to the server side by a client side in some HTTP request. That said, using JavaScript to gather required information of the current client environment like window size is unavoidable.

I presume the inner window width is required, because this is the client width determining the design of the content.

Now, JavaScript gets information on the window width via the property window.innerWidth. This is a standard property, see http://www.w3schools.com/jsref/obj_window.asp[^], but there are several kinds of incompatibilities like in IE, see for example http://www.javascriptkit.com/javatutors/static2.shtml[^], http://www.javascripter.net/faq/browserw.htm[^].

To avoid incompatibilities, I would use jQuery


(window).innerWidth().重要的是不要忘了最后的圆括号,因为在jQuery中这是一个函数.

请参见 http://api.jquery.com/innerWidth/ [
(window).innerWidth(). It''s important not to forget round brackets at the end, as in jQuery this is a function.

See http://api.jquery.com/innerWidth/[^].

The server side can get this information in different ways; the selection of the method should depend on the design and logic of your application. It could be sent as a form submission, AJAX or URL parameters.

onwayir写道:
onwayir wrote:

但是,问题在于某些移动系统-某些平台不支持JavaScript.
最后是什么专业建议? (js-php还是更好的方法?)
非常感谢. [OP的语法/拼写/大小写固定-SA]

Thanks, but the problem is that some mobile systems — some platforms do not support JavaScript.
At last what is the professional suggestion? (js-php or some better way?)
Lots of thanks. [OP''s grammar/spelling/capitalization fixed — SA]



首先,请不要发布解决方案,除非这确实是一个解决方案.在所有其他情况下,请使用上方的改善问题",添加评论或回复现有评论.

我不知道什么是"js-php",我怀疑这不是什么新鲜事,同样非常JavaScript与PHP结合在一起.我真的不知道没有PHP的浏览器(纯文本浏览器除外),但是事实是,甚至可以关闭JavaScript.在这种情况下,您很不走运-客户端上唯一普遍接受的标准是将EMCAScript实现为JavaScript.我想我已经在上面解释了为什么不使用JavaScript无法了解此类特定于客户端的详细信息的原因.
所以,你能做什么.我会说,使用更简单可靠的HTML/CSS设计.假设您仅使用段落和标题,仅调整字体样式和边距/填充样式,而没有绝对位置.它会独立于屏幕大小吗?是的,差不多.这种格式是可变的,它将采用屏幕本身的尺寸.同样,您可以通过与设备无关的方式进行更多格式化,并且仍然能够实现非常丰富的UI.只需记住它,并在不同大小的窗口上进行永久测试,只需调整浏览器窗口的大小即可.

作为免费赠品,这种设计将高度容忍浏览器不兼容. 不要害怕对用户的印象不足.大多数理性的人已经厌倦了功能强大的酷"设计.人们将对高度可读的功能性设计而不是高度图形化的难题感到更加满意.

—SA



First, please don''t post a solution, unless this is really a solution. In all other cases, use "Improve question" above, add a comment or reply to existing comment.

I don''t know what''s "js-php", I suspect this is nothing new, same very JavaScript combined with PHP. I don''t really know browsers without PHP (except text-only ones), but the truth is, JavaScript can be even switched off. In this case, you are out of luck — the only universally accepted standard on client side is EMCAScript implemented as JavaScript. I think I already explained above why you cannot know such client-specific detail without using JavaScript.

So, what could you do. I would say, use more simple and reliable HTML/CSS design. Imagine you only use paragraphs and headers, tweak only the font styles and margin/padding styles, no absolute positioning. Will it be screen-size independent? Yes, pretty much. Such format is fluid, it will adopt to screen size itself. Likewise, you can all a lot more formatting in such device-independent manner and still be able to achieve quite a rich UI. Just keep it in mind and permanently test on different windows sizes, simply resizing your browser window.

As a free bonus, such design will be highly tolerable to browser incompatibility. And don''t be afraid to be not enough impressive to the users. Most reasonable people were already fed up with beefed-up "cool" design. People would be more happy with highly readable and functional design, not highly graphical puzzles.

—SA


这篇关于在PHP中获取屏幕宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆