确定用户是否从移动Safari导航 [英] Determine if user navigated from mobile Safari

查看:145
本文介绍了确定用户是否从移动Safari导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用,我想根据用户导航的位置将用户重定向到不同的页面。

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

如果从网络剪辑导航,请执行此操作不重定向。
如果从移动版Safari导航,请重定向到safari.aspx。
如果从其他地方导航,请重定向到unavailable.aspx

If navigating from web clip, do not redirect. If navigating from mobile Safari, redirect to safari.aspx. If navigating from anywhere else, redirect to unavailable.aspx

我能够使用 iPhone WebApps,有没有办法检测它是如何加载的?主屏幕与Safari?确定用户是否从网络剪辑导航,但我无法确定用户是否在iPhone或iPod上从移动Safari导航。

I was able to use iPhone WebApps, is there a way to detect how it was loaded? Home Screen vs Safari? to determine if the user was navigating from a web clip, but I'm having trouble determining if the user navigated from mobile Safari on an iPhone or iPod.

这就是我所拥有的:

if (window.navigator.standalone) {
    // user navigated from web clip, don't redirect
}
else if (/*logic for mobile Safari*/) {
    //user navigated from mobile Safari, redirect to safari page
    window.location = "safari.aspx";
}
else {
    //user navigated from some other browser, redirect to unavailable page
    window.location = "unavailable.aspx";
}


推荐答案

UPDATE :这是一个非常古老的答案,我无法删除它,因为答案被接受了。请查看不知情的答案以获得更好的解决方案。

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
}

这篇关于确定用户是否从移动Safari导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆