Simple Object used to judge the client's attributes

Source: Internet
Author: User

Objects used in the program to determine client information

The requirement is not high, so it is relatively simple and not necessarily accurate.

In the game, you only need to determine whether Internet Explorer, Internet Explorer 6, and mobile phone functions.

This object can be used to determine the client operating system type, browser type, whether the client machine is a computer or mobile phone type, whether the access protocol is HTTP or FILE

Here, we only use it to determine that if the three systems are not windows, Mac, or Unix, they are mobile phones.

When the mobile phone is determined, the game automatically picks up the sun by default.

// User object, used to store the user's browser, operating system, and client type
$ User = function (){
Var platform = navigator. platform, userAgent = navigator. userAgent,
IsWin = (platform = 'win32 '| platform = "Windows "),
IsMac = (platform = 'mac68k' | platform = 'macppc '| platform = 'macintosh '),
IsUnix = (platform = 'x11 '&&! IsWin &&! IsMac ),
IsPC = isWin | isMac | isUnix;
Return {// the browser determines IE :!! (Window. attachEvent &&! Window. opera ),! -[1,]
Browser: {IE :!! (Window. attachEvent &&! Window. opera ),
IE6 :!! (Window. attachEvent &&! Window. opera )&&! Window. XMLHttpRequest,
Opera :!! Window. opera,
WebKit: userAgent. indexOf ('applewebkit/')>-1,
Gecko: userAgent. indexOf ('gecko ')>-1 & userAgent. indexOf ('khtml') =-1
},
// Operating System
System: {Win: isWin, Mac: isMac, Unix: isUnix },
// Client Machine Type
Client: {PC: isPC, Mobile :! IsPC },
// Obtain the address bar protocol, http Representation
HTTP: location. protocol. toLowerCase () = 'HTTP :'? 1:0
}
}()

Original: http://www.lonelystar.org/post/4.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.