开发者

Simple way to check whether user is mobile device?

开发者 https://www.devze.com 2023-02-23 15:40 出处:网络
I\'m looking to create a simple redirect on my homepage for users of major mobile OS (at least Android, Nokia/Symbian, Windows, iOS and Blackberry OS).

I'm looking to create a simple redirect on my homepage for users of major mobile OS (at least Android, Nokia/Symbian, Windows, iOS and Blackberry OS).

At present I have it working for iPhone / iPod (see below), but I'm wondering whether there's a simple way in javascript to check for all. (As opposed to just writing out a big ol list of mobile userAgents).

Perhaps something that detects screensize?

// Current Code
<script type="text/javascript">
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
    if (document.cookie.indexOf("iphone_redirect=false") == -1) {
        window.location = "http://m.domain.co.nz";
    开发者_如何学Python}
}
</script>


This properly done on the server, not on the client.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号