[ JavaScript ] ブラウザを判定するサンプル

ブラウザを判定して表示する JavaScript のサンプルです。

サンプルコード ———————————————————————-

<html><head>
<meta http-equiv="content-type" content="text/html;charset=x-sjis">
<title>Your Browsers</title>
<script language="JavaScript">
<!--
//determines which stylesheet to write based on 
//browser/platform combination.  Also sets global
//variable bp for browser/platform testing elsewhere.
if (navigator.platform.indexOf('Mac') > -1) {
    //mac
    if (navigator.appName.indexOf('Microsoft') > -1) {
        //explorer
        document.write('mac_ie');
} else {
        //netscape
        document.write('mac_nn');
    }
} else {
    //windows or unix
    if (navigator.appName.indexOf('Microsoft') > -1) {
        //explorer
        document.write('win_ie');
} else {
        //netscape
        document.write('win_nn');
    }
}
// -->
</script>
</head>
<body bgcolor="#ffffff">
</body>

実際に動作するサンプル ———————————————————————-

サンプルファイル

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です