Determine if user navigated from mobile Safari

后端 未结 12 682
情书的邮戳
情书的邮戳 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:24

    UPDATE: This is a very old answer and I cannot delete it because the answer is accepted. Check unwitting's answer below for a better solution.


    You should be able to check for the "iPad" or "iPhone" substring in the user agent string:

    var userAgent = window.navigator.userAgent;
    
    if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
       // iPad or iPhone
    }
    else {
       // Anything else
    }
    

提交回复
热议问题