Determine if user navigated from mobile Safari

后端 未结 12 694
情书的邮戳
情书的邮戳 2020-11-29 19:40

I have an app, and I\'d like to redirect the users to different pages based on where they are navigating from.

If navigating from web clip, do not redirect. If navig

12条回答
  •  暖寄归人
    2020-11-29 20:27

    Seeing all the answers, here are some tips about the proposed RegExes:

    • AppleWebKit matches Desktop Safari too (not only mobile)
    • no need to call .match more than once for such simple regexes, and prefer the lighter .test method.
    • the g (global) regex flag is useless while the i (case insensitive) can be useful
    • no need for capture (parenthesis), we are just testing the string

    I'm just using this since getting true for mobile Chrome is OK for me (same behavior):

    /iPhone|iPad|iPod/i.test(navigator.userAgent)
    

    (I just want to detect if the device is a target for an iOS app)

提交回复
热议问题