ブラウザの種類を読出し、MSIEだったらバージョンを読んでVer8以下かチェックする。
(サンプルではメッセージを表示する為、Ver8以上の場合にメッセージを出すようにしている。)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html lang= "ja" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=Shift_JIS" > <meta http-equiv= "Content-Style-Type" content= "text/css" > <title></title> <script language= "JavaScript" ><!-- myAgent = "" ; function myGetVer( myKey ){ myStart = myAgent.indexOf( myKey ) + myKey.length; myEnd = myAgent.indexOf( ";" , myStart ); return myAgent.substring ( myStart, myEnd ); } function mySearch( myKey ){ return (myAgent.indexOf( myKey )>=0) ? true : false ; } function myFunc( myUserAgent ){ myAgent = myUserAgent + ";" ; myAgent = myAgent.replace( / /g, ";" ); // Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; Touch; MAFSJS) if ( mySearch( "MSIE;" ) ) { alert( "ブラウザーはInternet Exploreです。" ); myVer = myGetVer( "MSIE;" ); myVerStr = "Versionは" + parseInt( myVer ); if (myVer >= 8 ) { alert( myVerStr ); document.write( "ご使用になっているInternet Exploreのバージョンは" , parseInt(myVer), "です。<br>当サイトの閲覧にはバージョン9.0以上ないしGoogle Chromeなど<br>他のブラウザーのご利用を推奨します。" ); } } } myParam = navigator.userAgent; myFunc( myParam ); // --></script> </head> <body> </body> </html> |
ブラウザの変更を勧めるメッセージを
ページに書く