根據(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)文章
詳解如何用babel轉(zhuǎn)換es6的class語法
這篇文章主要介紹了詳解如何用babel轉(zhuǎn)換es6的class語法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04
JavaScript識別網(wǎng)頁關(guān)鍵字并進行描紅的方法
這篇文章主要介紹了JavaScript識別網(wǎng)頁關(guān)鍵字并進行描紅的方法,通過字符串的遍歷、匹配及動態(tài)添加等操作實現(xiàn)識別與描紅的功能,非常簡單實用,需要的朋友可以參考下2015-11-11

