根據(jù)分辨率不同,調(diào)用不同的css文件
更新時(shí)間: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="";
引號(hào)里面分別填寫,用戶使用IE的時(shí)候并且分辨率為1024*768,800*600,1152*864要使用的css文件名.
var Firefox1024="";
var Firefox800="";
var Firefox1152="";
var Firefoxother="";
引號(hào)里面分別填寫,用戶使用FF的時(shí)候并且分辨率為1024*768,800*600,1152*864要使用的css文件名.
var Other1024="";
var Other800="";
var Other1152="";
var Otherother="";
引號(hào)里面分別填寫,用戶使用其他瀏覽器的時(shí)候并且分辨率為1024*768,800*600,1152*864要使用的css文件名.
不判斷分辨率,只判斷瀏覽器
應(yīng)E.Qiang提議,編如下代碼。實(shí)現(xiàn)根據(jù)瀏覽器類型自動(dòng)調(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語(yǔ)法
這篇文章主要介紹了詳解如何用babel轉(zhuǎn)換es6的class語(yǔ)法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04
js驗(yàn)證整數(shù)加保留小數(shù)點(diǎn)的簡(jiǎn)單實(shí)例
這篇文章主要介紹了js驗(yàn)證整數(shù)加保留小數(shù)點(diǎn)的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-12-12
關(guān)于JavaScript中URL對(duì)象的一些妙用
avaScript URL() 構(gòu)造函數(shù)返回一個(gè)新創(chuàng)建的 URL 對(duì)象,表示由一組參數(shù)定義的 URL,利用該構(gòu)造函數(shù)可以獲取 RL的查詢、參數(shù)等,下面這篇文章主要給大家介紹了關(guān)于JavaScript URL對(duì)象的一些妙用,需要的朋友可以參考下2021-10-10
JavaScript識(shí)別網(wǎng)頁(yè)關(guān)鍵字并進(jìn)行描紅的方法
這篇文章主要介紹了JavaScript識(shí)別網(wǎng)頁(yè)關(guān)鍵字并進(jìn)行描紅的方法,通過(guò)字符串的遍歷、匹配及動(dòng)態(tài)添加等操作實(shí)現(xiàn)識(shí)別與描紅的功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-11-11
JavaScript DOM節(jié)點(diǎn)添加示例
本節(jié)為大家介紹下JavaScript DOM節(jié)點(diǎn)添加,將node里面的str放到h1段落中使之成為h1的新段落2014-07-07

