如何确定 javascript 代码在哪个 iPhone 版本上运行? [英] How to determine which iPhone version the javascript code runs on?

查看:21
本文介绍了如何确定 javascript 代码在哪个 iPhone 版本上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要区分 iPhone3xiPhone4x.有什么办法可以从 JavaScript 中找出版本吗?

Need to distinguish between iPhone3x and iPhone4x. Is there any way to figure out the version from JavaScript please?

推荐答案

您可以使用 navigator.userAgent 来检查操作系统版本,但这并不是真正的问题.

You can use navigator.userAgent to check the OS version, but that isn't really the problem here.

您可以做的是使用媒体查询来检查设备的实际屏幕分辨率,这可能是导致当前问题的原因.

What you can do is use media queries to check the actual screen resolution of the device, which might be the cause of the problem at hand.

var isRetina = window.matchMedia("(-webkit-min-device-pixel-ratio: 2)").matches;

您也可以不用 JavaScript,通过使用媒体查询为 Retina 显示加载不同的样式表:

You could also probably do without JavaScript, by using media queries for loading different stylesheets for retina displays:

<link rel="stylesheet" href="retina.css"
    media="only screen and (-webkit-min-device-pixel-ratio: 2)" />

这篇关于如何确定 javascript 代码在哪个 iPhone 版本上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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