How to determine if iOS devices are redirected?

I am currently using this to determine if visitors are installed or not, and if not immediately, I assume that they are iPhone users, but now it seems that it does not always work as I want, because once they redirected to the flash version of my site, and once the person who received the flash drive also redirects the version of my site to the iPhone

<!DOCTYPE html> <html> <head> <script src="http://www.featureblend.com/flash_detect_1-0-4/flash_detect.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> if(!FlashDetect.installed){ window.location = "?flash=false"; }else{ window.location = "?flash=true"; } </script> </head> 

how can I determine if they are iPhone / iPad / iPod / AppleTV something like this and redirect them to a flash-fake URL, and if they are not listed above, will it be redirected to flash = true?

I tried to find, but really can not find what I'm looking for

Thanks and Merry X'Mas to all of you.

+4
source share
4 answers

There are many tutorials on how to achieve this. You can start here: http://www.hand-interactive.com/resources/detect-mobile-javascript.htm

In short, you can simply search for the lines "iphone", "ipod", "ipad", etc. in a user agent line with code like this:

 var uagent = navigator.userAgent.toLowerCase(); if (uagent.search("iphone") > -1 || uagent.search("ipod") > -1 || uagent.search("ipad") > -1 || uagent.search("appletv") > -1) { window.location = "?flash=false"; } else { window.location = "?flash=true"; } 

Merry Christmas to you too :)

+8
source

Try using something similar to

 var agent=navigator.userAgent.toLowerCase(); var is_iphone = ((agent.indexOf('iphone')!=-1); if (is_iphone) { conditional code goes here } 

Refresh . You can also redirect the user using the .htaccess file. This htaccess rule will check if the user is using an iPhone, and if so, redirect it to the "iphone" subdomain

 RewriteEngine on RewriteCond %{HTTP_USER_AGENT} iPhone RewriteRule .* http://iphone.mydomain.com/ [R] 

If you do not know how to use .htaccess files here - this is a blog post that I wrote earlier about this.

To add additional devices, add code similar to JavaScript:

 var agent=navigator.userAgent.toLowerCase(); var is_iphone = ((agent.indexOf('iphone')!=-1); var is_ipad = ((agent.indexOf('ipad')!=-1); if (is_iphone || ipad) { conditional code goes here } 

.htaccess

 RewriteEngine on RewriteCond %{HTTP_USER_AGENT} iPhone RewriteCond %{HTTP_USER_AGENT} iPad RewriteRule .* http://ios.mydomain.com/ [R] 
+3
source

I had a similar problem trying to dynamically load javascript files only when the user was on iOS / Safari, this is what I came up with:

 <script> //include jquery when mobile. var isIOS = navigator.userAgent.match(/iPad/i) != null || navigator.userAgent.match(/iPhone/i) != null; if(isIOS){ var script = document.createElement('script'); script.type='text/javascript'; script.src = 'js/jquery.min.js'; document.getElementsByTagName('head')[0].appendChild(script); } </script> 
+2
source

Check the User-Agent string to determine the device that the user is using and redirecting accordingly. You will need to check all devices, iphone, ipad, ipod, appletv, etc.

+1
source

Source: https://habr.com/ru/post/1387955/


All Articles