根據(jù)分辨率不同,調(diào)用不同的css文件
更新時間:2006年08月25日 00:00:00 作者:
dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0> <SCRIPT LANGUAGE="javascript">
<!--
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
var IE1024="";
var IE800="";
var IE1152="";
var IEother="";
ScreenWidth(IE1024,IE800,IE1152,IEother)
}else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
file://如果瀏覽器為Firefox
var Firefox1024="";
var Firefox800="";
var Firefox1152="";
var Firefoxother="";
ScreenWidth(Firefox1024,Firefox800,Firefox1152,Firefoxother)
}else{
file://如果瀏覽器為其他
var Other1024="";
var Other800="";
var Other1152="";
var Otherother="";
ScreenWidth(Other1024,Other800,Other1152,Otherother)
}
}
function ScreenWidth(CSS1,CSS2,CSS3,CSS4){
if ((screen.width == 1024) && (screen.height == 768)){
setActiveStyleSheet(CSS1);
}else{
if ((screen.width == 800) && (screen.height == 600)){
setActiveStyleSheet(CSS2);
}else{
if ((screen.width == 1152) && (screen.height == 864)){
setActiveStyleSheet(CSS3);
}else{
setActiveStyleSheet(CSS4);
}}}
}
function setActiveStyleSheet(title){
document.getElementsByTagName("link")[0].href="style/"+title;
}
file://-->
</SCRIPT>
解釋:
var IE1024="";
var IE800="";
var IE1152="";
var IEother="";
引號里面分別填寫,用戶使用IE的時候并且分辨率為1024*768,800*600,1152*864要使用的css文件名.
var Firefox1024="";
var Firefox800="";
var Firefox1152="";
var Firefoxother="";
引號里面分別填寫,用戶使用FF的時候并且分辨率為1024*768,800*600,1152*864要使用的css文件名.
var Other1024="";
var Other800="";
var Other1152="";
var Otherother="";
引號里面分別填寫,用戶使用其他瀏覽器的時候并且分辨率為1024*768,800*600,1152*864要使用的css文件名.
不判斷分辨率,只判斷瀏覽器
應(yīng)E.Qiang提議,編如下代碼。實現(xiàn)根據(jù)瀏覽器類型自動調(diào)用不同CSS。
代碼:
<SCRIPT LANGUAGE="javascript">
<!--
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
file://如果瀏覽器為IE
setActiveStyleSheet("default.css");
}else{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
{
file://如果瀏覽器為Firefox
setActiveStyleSheet("default2.css");
}else{
file://如果瀏覽器為其他
setActiveStyleSheet("newsky.css");
}
}
function setActiveStyleSheet(title){
document.getElementsByTagName("link")[0].href="style/"+title;
}
file://-->
</SCRIPT>
解釋:
如果瀏覽器為IE,則調(diào)用default.css
如果瀏覽器為Firefox,則調(diào)用default2.css
如果瀏覽器為其他,則調(diào)用newsky.css
用法:放在<head></head>中即可。
相關(guān)文章
JavaScript Event學(xué)習(xí)第七章 事件屬性
為了理解Event屬性,我將在這里給出一些示例代碼。在這個范疇內(nèi)有非常嚴(yán)重的瀏覽器兼容性問題。2010-02-02在服務(wù)端(Page.Write)調(diào)用自定義的JS方法詳解
自從[javascript]自定義MessageBox一文發(fā)布以后,很多網(wǎng)友都來信詢問,如何在服務(wù)端調(diào)用ShowInfo方法,周末休息想了個折中的辦法來實現(xiàn)2013-08-08根據(jù)表格中的某一列進行排序的javascript代碼
根據(jù)表格中的某一列進行排序的實現(xiàn)方法有很多,下面為大家介紹下如何使用js來簡單實現(xiàn)下,需要的朋友不要錯過2013-11-11