<small id='hBWuf'></small><noframes id='hBWuf'>

<i id='hBWuf'><tr id='hBWuf'><dt id='hBWuf'><q id='hBWuf'><span id='hBWuf'><b id='hBWuf'><form id='hBWuf'><ins id='hBWuf'></ins><ul id='hBWuf'></ul><sub id='hBWuf'></sub></form><legend id='hBWuf'></legend><bdo id='hBWuf'><pre id='hBWuf'><center id='hBWuf'></center></pre></bdo></b><th id='hBWuf'></th></span></q></dt></tr></i><div id='hBWuf'><tfoot id='hBWuf'></tfoot><dl id='hBWuf'><fieldset id='hBWuf'></fieldset></dl></div>
    <bdo id='hBWuf'></bdo><ul id='hBWuf'></ul>

    1. <tfoot id='hBWuf'></tfoot>
    2. <legend id='hBWuf'><style id='hBWuf'><dir id='hBWuf'><q id='hBWuf'></q></dir></style></legend>

      检测 iPhone 5 及其下方的任何 iOS 设备

      时间:2023-05-30

      1. <legend id='IJ10V'><style id='IJ10V'><dir id='IJ10V'><q id='IJ10V'></q></dir></style></legend>

        <small id='IJ10V'></small><noframes id='IJ10V'>

      2. <tfoot id='IJ10V'></tfoot>
          <bdo id='IJ10V'></bdo><ul id='IJ10V'></ul>
                <tbody id='IJ10V'></tbody>

                <i id='IJ10V'><tr id='IJ10V'><dt id='IJ10V'><q id='IJ10V'><span id='IJ10V'><b id='IJ10V'><form id='IJ10V'><ins id='IJ10V'></ins><ul id='IJ10V'></ul><sub id='IJ10V'></sub></form><legend id='IJ10V'></legend><bdo id='IJ10V'><pre id='IJ10V'><center id='IJ10V'></center></pre></bdo></b><th id='IJ10V'></th></span></q></dt></tr></i><div id='IJ10V'><tfoot id='IJ10V'></tfoot><dl id='IJ10V'><fieldset id='IJ10V'></fieldset></dl></div>
                本文介绍了检测 iPhone 5 及其下方的任何 iOS 设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                一个 问题 被问到关于 iPhone 4 用户的 SO代理和 iOS 5.0 用户代理.

                A question was asked on SO about the iPhone 4 user agent and the iOS 5.0 user agent.

                我使用以下方法来检测不同的移动设备、视口和屏幕.

                I use the following to detect different mobile devices, viewport and screen.

                我希望能够区分 iPhone 5 和所有其他 iOS 设备.据我所知,我用来检测 iOS 5.0 用户代理 var iPhone5 的行也适用于任何运行 iOS 5.0 的 iOS 设备,所以从技术上讲它是不正确的.

                I'd like to be able to distinguish between the iPhone 5 and all other iOS devices. As far as I know, the line I'm using to detect the iOS 5.0 user agent var iPhone5 would also apply to any iOS device running iOS 5.0, so technically it's incorrect.

                var pixelRatio = window.devicePixelRatio || 1;
                
                var viewport = {
                    width: window.innerWidth,
                    height: window.innerHeight
                };
                
                var screen = {
                    width: window.screen.availWidth * pixelRatio,
                    height: window.screen.availHeight * pixelRatio
                };
                
                var iPhone = /iPhone/i.test(navigator.userAgent);
                var iPhone4 = (iPhone && pixelRatio == 2);
                var iPhone5 = /iPhone OS 5_0/i.test(navigator.userAgent); // ?
                var iPad = /iPad/i.test(navigator.userAgent);
                var android = /android/i.test(navigator.userAgent);
                var webos = /hpwos/i.test(navigator.userAgent);
                var iOS = iPhone || iPad;
                var mobile = iOS || android || webos;
                

                window.devicePixelRatio 是设备上的物理像素和与设备无关的像素(倾角)之间的比率.window.devicePixelRatio = 物理像素/倾角.

                window.devicePixelRatio is the ratio between physical pixels and device-independent pixels (dips) on the device. window.devicePixelRatio = physical pixels / dips.

                更多信息这里.

                推荐答案

                为什么不根据屏幕对象检测-

                Why don't you detect based on the screen object -

                screen.availWidth
                screen.availHeight
                

                在我的 iPhone 5 上,它报告宽度为 320,高度为 548,这是它在非视网膜形式下的分辨率.

                On my iPhone 5 it reports 320 width and 548 height, which is its resolution in a non-retina form.

                您不应使用 window.innerWidth 和 window.innerHeight,因为它会报告视口大小.如果页面被放大,它会报告放大区域的大小,而不是可用屏幕的正确大小.

                You should NOT use window.innerWidth and window.innerHeight due to it reporting the viewport size. If the page is zoomed in, it will report the size of the zoomed in area, and not the proper size of the available screen.

                这篇关于检测 iPhone 5 及其下方的任何 iOS 设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 Phonegap 访问文件 下一篇:使用 capinsets 调整图像大小

                相关文章

                最新文章

                • <bdo id='c5llR'></bdo><ul id='c5llR'></ul>
              • <small id='c5llR'></small><noframes id='c5llR'>

                <legend id='c5llR'><style id='c5llR'><dir id='c5llR'><q id='c5llR'></q></dir></style></legend>

              • <tfoot id='c5llR'></tfoot>
                <i id='c5llR'><tr id='c5llR'><dt id='c5llR'><q id='c5llR'><span id='c5llR'><b id='c5llR'><form id='c5llR'><ins id='c5llR'></ins><ul id='c5llR'></ul><sub id='c5llR'></sub></form><legend id='c5llR'></legend><bdo id='c5llR'><pre id='c5llR'><center id='c5llR'></center></pre></bdo></b><th id='c5llR'></th></span></q></dt></tr></i><div id='c5llR'><tfoot id='c5llR'></tfoot><dl id='c5llR'><fieldset id='c5llR'></fieldset></dl></div>