我目前正在使用它来检测访问者是否安装了flash,如果没有,我假设他们是iPhone用户,但现在它似乎并不总是像我希望的那样工作,因为有时他们被重定向到我网站的flash版本,有时安装flash的人也重定向到我网站的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>问题是,我如何检测它们是否是iPhone/iPad/iPod/AppleTV之类的东西,并将它们重定向到flash=false URL,如果它们不是上面提到的,就会重定向到flash=true?
我试着去找,但真的找不到我要找的东西
谢谢你和快乐的X‘’Mas给你们所有人。
发布于 2011-12-26 04:29:45
有很多关于如何实现这一点的教程。您可以从这里开始:http://www.hand-interactive.com/resources/detect-mobile-javascript.htm
简而言之,你可以简单地查找字符串"iphone","ipod","ipad“等……添加到用户代理字符串中,代码如下所示:
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";
}也祝你圣诞快乐:)
发布于 2011-12-26 04:27:11
尝试使用类似于
var agent=navigator.userAgent.toLowerCase();
var is_iphone = ((agent.indexOf('iphone')!=-1);
if (is_iphone) { conditional code goes here }更新:您还可以使用.htaccess文件重定向用户。此htaccess规则将检查用户是否正在使用iPhone,如果是,则重定向到子域'iphone‘
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteRule .* http://iphone.mydomain.com/ [R]如果你不知道如何使用.htaccess文件,here是我之前写的一篇关于它的博客文章。
要添加更多设备,请添加类似于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]发布于 2014-07-16 04:55:47
当用户在IOS/safari上时,我尝试动态加载javascript文件时也遇到了类似的问题,这就是我想出来的:
<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>https://stackoverflow.com/questions/8631392
复制相似问题