Today, I saw a browser that I used a long time ago on csdn, but most of them failed. Now I have modified it. I have tested several browsers on my local machine.
VaR sys = {},
UA = navigator. useragent;
If (window. activexobject)
SYS. Ie = UA. Match (/MSIE ([\ D.] +)/) [1]
Else if (window. Google & window. Chrome ){
SYS. Chrome = UA. Match (/chrome \/([\ D.] +)/) [1]}
Else if (window. components)
SYS. Firefox = UA. Match (/Firefox \/([\ D.] +)/) [1]
Else if (window. Opera)
SYS. Opera = UA. Match (/opera. ([\ D.] +)/) [1]
Else if (! Navigator. taintenabled)
SYS. Safari = UA. Match (/version \/([\ D.] +)/) [1];
// Perform the following tests:
If (SYS. ie) document. Write ('ie: '+ SYS. ie );
If (SYS. Firefox) document. Write ('Firefox: '+ SYS. Firefox );
If (SYS. Chrome) document. Write ('chrome: '+ SYS. Chrome );
If (SYS. Opera) document. Write ('Opera: '+ SYS. Opera );
If (SYS. Safari) document. Write ('safari: '+ SYS. Safari );
We sorted out one more Feature Detection:
VaR browser = function () {// try to use features for Detection
VaR UA = navigator. useragent,
B = {
IE :!! Window. activexobject,
//! + '\ V1'
//!! Window. vbarray
IE6 :! "1" [0],
Ie67:/MSIE [67]/. Test (UA ),
Ie9 :!! Document.doc umentmode & document.doc umentmode = 9,
Chrome :!! (Window. Google & window. Chrome ),
Firefox :!! Window. components,
Safari :!! Navigator. Vendor &&! Top. Chrome ,//(! Navigator. taintenabled &&! Window. Chrome), the strange IE6/7 error,
Opera :!! Window. opera,
Version: (UA. Match (/\ s + (? : MSIE | chrome | Firefox | Version) [\/] ([\ D.] +)/) | [0, 0]) [1]
};
Return B
}()
// Display the result
Document. Write ("<br/>" + navigator. useragent + "<br/> ")
VaR c = browser;
For (var n in c ){
Document. Write (n + ":" + C [N] + "<br/> ")
}
UA Detection:
VaR BB = function (){
VaR UA = navigator. useragent,
Check = function (r) {return R. Test (UA )},
B = {
IE: Check (/MSIE /),
IE6: Check (/MSIE 6 /),
Ie67: Check (/MSIE [67]/),
Ie9: Check (/MSIE 9 /),
Chrome: Check (/Chrome /),
Firefox: Check (/Firefox /),
Safari: Check (/Safari /)&&! Top. Chrome,
Opera: Check (/Opera /),
Version: (UA. Match (/\ s + (? : MSIE | chrome | Firefox | Version) [\/] ([\ D.] +)/) | [0, 0]) [1]
};
Return B
}()
Related links:
Javascript browser judgment
Browser detect