高級JavaScript例01
3343 ワード
ブラウザとバージョンを検出
<html>
<body>
<script type="text/javascript">
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
document.write(" :"+ browser)
document.write("<br />")
document.write(" :"+ version)
</script>
</body>
</html>
ブラウザの詳細を検出<html>
<body>
<script type="text/javascript">
document.write("<p> :")
document.write(navigator.appName + "</p>")
document.write("<p> :")
document.write(navigator.appVersion + "</p>")
document.write("<p> :")
document.write(navigator.appCodeName + "</p>")
document.write("<p> :")
document.write(navigator.platform + "</p>")
document.write("<p>Cookies :")
document.write(navigator.cookieEnabled + "</p>")
document.write("<p> :")
document.write(navigator.userAgent + "</p>")
</script>
</body>
</html>
ブラウザのすべての情報を検出<html>
<body>
<script type="text/javascript">
var x = navigator;
document.write("CodeName=" + x.appCodeName);
document.write("<br />");
document.write("MinorVersion=" + x.appMinorVersion);
document.write("<br />");
document.write("Name=" + x.appName);
document.write("<br />");
document.write("Version=" + x.appVersion);
document.write("<br />");
document.write("CookieEnabled=" + x.cookieEnabled);
document.write("<br />");
document.write("CPUClass=" + x.cpuClass);
document.write("<br />");
document.write("OnLine=" + x.onLine);
document.write("<br />");
document.write("Platform=" + x.platform);
document.write("<br />");
document.write("UA=" + x.userAgent);
document.write("<br />");
document.write("BrowserLanguage=" + x.browserLanguage);
document.write("<br />");
document.write("SystemLanguage=" + x.systemLanguage);
document.write("<br />");
document.write("UserLanguage=" + x.userLanguage);
</script>
</body>
</html>
ブラウザの種類に応じてユーザに警告する<html>
<head>
<script type="text/javascript">
function detectBrowser()
{
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=4))
{alert(" !")}
else
{alert(" !")}
}
</script>
</head>
<body onload="detectBrowser()">
</body>
</html>