开发者

Simple way to check whether user is mobile device?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜