Determine if user navigated from mobile Safari

后端 未结 12 706
情书的邮戳
情书的邮戳 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条回答
  •  猫巷女王i
    2020-11-29 20:34

    I was looking for this answer and I remembered I came across this before.

    The most reliable way to detect Safari on iOS in JavaScript is

    if (window.outerWidth === 0) {
        // Code for Safari on iOS
    } 
    
    or 
    
    if (window.outerHeight === 0) {
        // Code for Safari on iOS
    } 
    

    For some reason Safari on iOS returns 0 for window.outerHeight property and window.outerWidth property.

    This is for all iPads and iPhones on all versions of iOS. Every other browser and device this property works normally.

    Not sure if they intend to change this but for now it works well.

提交回复
热议问题