Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  94] [ 3]  / answers: 1 / hits: 88326  / 14 Years ago, wed, june 9, 2010, 12:00:00

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 navigating from mobile Safari, redirect to safari.aspx.
If navigating from anywhere else, redirect to unavailable.aspx



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.



Here's what I have:



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;
}

More From » iphone

 Answers
120

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
}

[#96549] Saturday, June 5, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parisc

Total Points: 438
Total Questions: 119
Total Answers: 119

Location: Turkmenistan
Member since Sat, Apr 16, 2022
2 Years ago
;