maga
V2EX  ›  问与答

在前端判断 iPhone -4 与 iPhone -5 的办法

  •  
  •   maga · May 9, 2014 · 4121 views
    This topic created in 4439 days ago, the information mentioned may be changed or developed.
    为iphone-4与5做了两套图,想各自加载不同的<img src>, 在前端有什么办法区分这两者吗?在后端通过user-agent可以判断,但感觉不是特别好的办法,增加了后端的逻辑。
    Supplement 1  ·  May 9, 2014
    谢谢各位,window.screen.height来判断,解决问题
    + $(window).ready(function() {
    + var height = window.screen.height;
    + console.log(height);
    + if (height <= 480) {
    + console.log(height);
    + $('#slide_00').attr("src", "img/4000.png")
    + $('#slide_01').attr("src", "img/4001.png")
    + $('#slide_02').attr("src", "img/4002.png")
    + $('#slide_03').attr("src", "img/4003.png")
    + }
    + });
    9 replies    2014-05-09 13:01:09 +08:00
    qdvictory
        1
    qdvictory  
       May 9, 2014
    是判断ip还是判断页面高度?
    luo123qiu
        2
    luo123qiu  
       May 9, 2014
    根据窗口高度来判断吧。
    jsonline
        3
    jsonline  
       May 9, 2014 via Android
    iPhone 负4?
    NemoAlex
        4
    NemoAlex  
       May 9, 2014
    navigator.userAgent
    iPhone 4 和 5 这个有区别么?
    jiangpeng
        5
    jiangpeng  
       May 9, 2014
    userAgent 只会知道是 iPhone 还是 iPad,还是得窗口高度啊
    kamal
        6
    kamal  
       May 9, 2014
    iPhone 4 UA
    Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7

    iPhone 5 UA
    Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3

    iPhone OS 4_0
    iPhone OS 5_0
    jiangpeng
        7
    jiangpeng  
       May 9, 2014
    @kamal 这是 iOS 的版本吧……
    kamal
        8
    kamal  
       May 9, 2014   ❤️ 1
    iamocean
        9
    iamocean  
       May 9, 2014   ❤️ 1
    window.screen.height > 480 ? iphone5 : iphone4;
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2913 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 07:43 · PVG 15:43 · LAX 00:43 · JFK 03:43
    ♥ Do have faith in what you're doing.