/ Published in: JavaScript
Support: Fx2, Opera9, IE6
I don't have warrant of Safari's run and NN4. However, I think that this code is perhaps safe.
I don't have warrant of Safari's run and NN4. However, I think that this code is perhaps safe.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/*----------------------------------------------------------------------------- * Navigator * Example Source document.write( (Navigator.isWinIE()) ? 'IE' + Navigator.isWinIE() + ' (Win)' : (Navigator.isMacIE()) ? 'IE' + Navigator.isMacIE() + ' (Mac)' : (Navigator.isGecko()) ? 'Mozilla (' + Navigator.isGecko() + ')' : (Navigator.isSafari()) ? 'Safari (' + Navigator.isSafari() + ')' : (Navigator.isKDE()) ? 'KDE (' + Navigator.isKDE() + ')' : (Navigator.isOpera()) ? 'Opera' + Navigator.isOpera() : (Navigator.isNN4()) ? 'NN4' : "I don't know." ); *-------------------------------------------------------------------------- */ var Navigator = { _getVersion: function (a, b) { var t = navigator.userAgent.split(a)[1]; return (t) ? t.split(b)[0] : false; }, isOpera: function () { return ( (window.opera) ? (document.createElementNS) ? (document.createCDATASection) ? (document.styleSheets) ? 9 : 8 : 7 : 6 : false ); }, isSafari: function () { return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('AppleWebKit/', '(') : false; }, isKDE: function () { return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('Konqueror/', ';') : false; }, isGecko: function () { return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('Gecko/', ' ') : false; }, isNN4: function () { return (document.layers && typeof document.layers == 'object') ? true : false; }, isWinIE: function () { return ( /*@cc_on @if (@_win64 || @_win32 || @_win16) (document.getElementsByTagName) ? (@_jscript_version > 5.6) ? 7 : (@_jscript_version == 5.6) ? 6 : (@_jscript_version == 5.5) ? 5.5 : 5 : 4 @else@*/false/*@end @*/ ); }, isMacIE: function () { return ( /*@cc_on @if (@_mac && (@_PowerPC || @_mc680x0)) (document.getElementsByTagName) ? 5 : 4 @else@*/false/*@end @*/ ); } };