2007年4月16日 星期一

根據瀏覽器類型調用css樣式

內容來源:http://www.shou-nao.com/tw/charles/article.cfm?ATC_ID=E477A780-934F-2EAA-1011F1F9BE3E3302


if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
//如果瀏覽器为IE
setActiveStyleSheet("default.css");
}else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
//如果瀏覽器为Firefox
setActiveStyleSheet("default2.css");
}else{
//如果瀏覽器为其他
setActiveStyleSheet("newsky.css");
}
}

function setActiveStyleSheet(title){
document.getElementsByTagName("link")[0].href="style/"+title;
}




解釋:
如果瀏覽器为IE,則用default.css
如果瀏覽器为Firefox,則用default2.css
如果瀏覽器为其他,則用newsky.css

沒有留言: