ブラウザ判別スクリプト
ブラウザ別にcssを読み込みたいのですが、
firefox2.0に反映されません。
どうしてでしょうか?
<!--ブラウザ判別
function getOSType()
{
var uAgent = navigator.userAgent.toUpperCase();
if (uAgent.indexOf("MAC") >= 0) return "MacOS";
if (uAgent.indexOf("WIN") >= 0) return "Windows";
if (uAgent.indexOf("X11") >= 0) return "UNIX";
return "";
}
// Netscape Navigator -> Netscape
// Internet Explorer -> Explorer
// Safari -> Safari
// Opera -> Opera
function getBrowserName()
{
var aName = navigator.appName.toUpperCase();
var uName = navigator.userAgent.toUpperCase();
if (uName.indexOf("SAFARI") >= 0) return "Safari";
if (aName.indexOf("MICROSOFT") >= 0) return "Explorer";
if (uName.indexOf("FIREFOX") >= 0) return "Firefox";
return "";
}
function getBrowserVersion()
{
var browser = getBrowserName();
var version = 0;
var s = 0;
var e = 0;
var appVer = navigator.appVersion;
var uName = navigator.userAgent.toUpperCase();
if (browser == "Safari")
{
version = eval(appVer.substring(0,3)) - 4;
}
if (browser == "Explorer")
{
appVer = navigator.userAgent;
s = appVer.indexOf("MSIE ",0) + 5;
e = appVer.indexOf(";",s);
version = eval(appVer.substring(s,e));
}
if (browser == "Firefox")
{
s = uName.indexOf("FIREFOX/",0);
version = parseFloat(uName.substring(s+8,s+8+3));
}
return version;
}
//-->
<!--top.js
os = getOSType();
browser = getBrowserName();
version = getBrowserVersion();
if (os == "MacOS") dirName = "css/mac/";
if (os == "Windows") dirName = "css/win/";
if (os == "UNIX") dirName = "css/unix/";
if (browser == "Explorer") dirName += "ie";
if (browser == "Safari") dirName += "saf";
if (browser == "Firefox") dirName += "ff";
if ((version >= 1) && (version < 2)) dirName += "top.css";
if ((version >= 2) && (version < 3)) dirName += "top.css";
if ((version >= 3) && (version < 4)) dirName += "top.css";
if ((version >= 4) && (version < 5)) dirName += "top.css";
if ((version >= 5) && (version < 5.5)) dirName += "top.css";
if ((version >= 5.5) && (version < 6)) dirName += "top.css";
if ((version >= 6) && (version < 7)) dirName += "top.css";
if ((version >= 7) && (version < 8)) dirName += "top.css";
document.write("<link rel='stylesheet' href='"+dirName+"' type='text/css'>");
//-->
お礼
運ですよね…