Forum Moderators: open
<script type="text/javascript">
if ((navigator.userAgent.indexOf('iPhone') != -1) ¦¦
(navigator.userAgent.indexOf('iPod') != -1)) {
document.location = "http://www.example.com/";
}
</script>
I then have a link on the iPhone site that lets the user view the main site, although it's not really optimised for the iPhone. The only trouble is when they click that link it then takes them to the index page which obviously has the detection script and so forwards them to the iPhone site!
Is there anything I can do to get around this?
[edited by: Fotiman at 5:42 pm (utc) on Nov. 7, 2008]
[edit reason] Examplified URL [/edit]
1. Check the document.referrer to see if the user is coming from your redirect site:
if ((navigator.userAgent.indexOf('iPhone') != -1) ¦¦
(navigator.userAgent.indexOf('iPod') != -1)) {
if (document.referrer.indexOf('http://www.example.com/') == -1) {
// Not coming from example.com so redirect
document.location = 'http://www.example.com/';
}
}
2. Another alternative would be to pass a value in the query string on the link to direct them back to your site, and then look for that value before redirecting (similar to the referrer check above).
Hope that helps.
Check for the cookie before you do the redirect and if it exists then don't do the redirect.
You can store the cookie for a while that way when they come back to your site they don't have to click the link everytime.
Also you should add this as well
navigator.userAgent.indexOf('mini') != -1
It will catch all the Opera minis versions which is used on a lot of phones for web browsing.
[edited by: Demaestro at 9:01 pm (utc) on Nov. 7, 2008]