如何使用 JavaScript 检测手持设备 iOS 浏览器

How to detect handheld device iOS browsers with JavaScript?

本文关键字:iOS 浏览器 何使用 JavaScript 检测      更新时间:2023-09-26

我希望当我用iPhone浏览我的网站时,我的iPhone得到比我用Mac冲浪时更多的文本

<script type="text/javascript">
if ((navigator.userAgent.match(/iPhone/i))
       || (navigator.userAgent.match(/iPod/i))
       || (navigator.userAgent.match(/iPad/i))) {
    document.write("you are surfing with an iPhone");
} else {
    document.write("you are not surfing with an iPhone")
}
</script>

这是行不通的。有人可以帮助我吗?

对不起,我的英语不好,我来自比利时,法兰德斯

if (navigator.userAgent.match(/iPhone/i)
    || navigator.userAgent.match(/iPod/i)
    || navigator.userAgent.match(/iPad/i))
{
     alert("It's an iPhone or iPod");
}

工作是一种享受,我刚刚使用jsFiddle在我的iPhone上测试了它。​