用js如何判断打开网页的是安卓还是ios?
我要做个html页面,有个链接下载app,如果是苹果手机打开就下载ios版安卓就下载安卓版,
如何用js区分?
<code><script type = "text/javascript">
$(function(){
var ua = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/.test(ua)) {
$("a").attr("href","https://itunes.apple.com/us/app/ren-ren-duo-bao-yi-ge-shou/id1111430715?l=zh&ls=1&mt=8");
} else {
$("a").attr("href","http://www.rrdb8.com/statics/templates/app/RenRenDuoBao.apk");
}
})
</script>
做出来了
</code>用js如何判断打开网页的是安卓还是ios?
我要做个html页面,有个链接下载app,如果是苹果手机打开就下载ios版安卓就下载安卓版,
如何用js区分?
<code><script type = "text/javascript">
$(function(){
var ua = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/.test(ua)) {
$("a").attr("href","https://itunes.apple.com/us/app/ren-ren-duo-bao-yi-ge-shou/id1111430715?l=zh&ls=1&mt=8");
} else {
$("a").attr("href","http://www.rrdb8.com/statics/templates/app/RenRenDuoBao.apk");
}
})
</script>
做出来了
</code>
呃,我之前判断过android和iPhone,直接判断UA,如果是iOS的话,参考其他人的答案
立即学习“Java免费学习笔记(深入)”;
<code>function getOS(){
var ua = window.navigator.userAgent.toLowerCase(),
iPhone = /iphone/i.test(ua) ? true : false,
android = /android/i.test(ua) ? true : false;
return {android:android, iPhone:iPhone};
}</code>
https://github.com/matthewhudson/device.js可以试试这个库
var userAgent = navigator.userAgent;
var isAndroid = userAgent.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!userAgent.match(/(i1+;( U;)? CPU.+Mac OS X/); //ios终端
根据isAndroid,isiOS为 1 或者 0 就可以做出判断。
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号