简体   繁体   English

如何在没有JavaScript的情况下检测屏幕分辨率?

[英]How to detect screen resoluion without javascript?

In case i want to check user's device by its resolution(ie 300x600px for mobile, 800x600px for tab, and 1024x768px for pc). 如果我想通过其分辨率检查用户的设备(例如,移动设备为300x600px,标签为800x600px,个人计算机为1024x768px)。

but, how can i get the user's screen resolution when their javascript is disabled? 但是,当禁用JavaScript时,如何获得用户的屏幕分辨率?

or is there any other way to solve my problem? 还是有其他方法可以解决我的问题?

您可以使用CSS媒体查询来应用针对某些屏幕分辨率和方向的CSS规则。

@media should do it @media应该这样做

By your specs: 根据您的规格:

@media (max-width: 799px) {
  @import url("/uri/to/mobile.css");
}
@media (min-width: 800px) {
  @import url("uri/to/tablet.css");
}
@media (min-width: 1024) {
  @import url("/uri/to/desktop.css");
}

I dont think you need to create diffrent pages for eaxh reslolution juat use CSS media queries for adjust page according layout. 我不认为您需要为eaxh relolution juat创建不同的页面,而使用CSS媒体查询来根据布局调整页面。

If you want diffrent page per resolution then you have to use some server side lib or function to detect browser resolution 如果您希望每个分辨率的页面不同,则必须使用某些服务器端库或函数来检测浏览器分辨率

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM