お手軽 ブラウザバージョン判定

getBrowserVersion() は、ブラウザのバージョン番号(Major[.Minor])を返します。

<html><head><title></title></head><body>
<script>
function getBrowserVersion() { // @return Number:
  return window.opera ? (opera.version().replace(/\d$/, "") - 0) // Opera10 shock
                      : parseFloat((/(?:IE |fox\/|ome\/|ion\/)(\d+\.\d)/.
                                   exec(navigator.userAgent) || [,0])[1]);
}
window.onload = function() {
  alert(getBrowserVersion());
}
</script>
</body></html>
Browser Result value
Google Chrome3 3
Safari4β 4
Firefox2 2
Firefox3.5 3.5
IE5.5 5.5
IE6 6
IE7 7
IE8(IE7モード) 7
IE8(IE8モード) 8
Opera9.27 9.2
Opera10β 10

IE8(IE8モード)を判定するには、以下のようにします。

if (document.documentMode >= 8) {
// IE8 mode
}