根據(jù)判斷瀏覽器類型屏幕分辨率自動調(diào)用不同CSS的代碼
更新時間:2007年02月22日 00:00:00 作者:
既判斷分辨率,也判斷瀏覽器
重新完善代碼,使之成為判斷瀏覽器類型屏幕分辨率自動調(diào)用不同CSS的代碼。
解釋:
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文件名.
不判斷分辨率,只判斷瀏覽器
實現(xiàn)根據(jù)瀏覽器類型自動調(diào)用不同CSS。
解釋:
如果瀏覽器為IE,則調(diào)用default.css
如果瀏覽器為Firefox,則調(diào)用default2.css
如果瀏覽器為其他,則調(diào)用newsky.css
用法:
放在
[codes=xml]</head>[/codes]
前面即可。
只判斷分辨率,不判斷瀏覽器
重新完善代碼,使之成為判斷瀏覽器類型屏幕分辨率自動調(diào)用不同CSS的代碼。
復(fù)制代碼 代碼如下:
<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)
{
//如果瀏覽器為Firefox
var Firefox1024="";
var Firefox800="";
var Firefox1152="";
var Firefoxother="";
ScreenWidth(Firefox1024,Firefox800,Firefox1152,Firefoxother)
}else{
//如果瀏覽器為其他
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;
}
//-->
</SCRIPT>
<!--
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)
{
//如果瀏覽器為Firefox
var Firefox1024="";
var Firefox800="";
var Firefox1152="";
var Firefoxother="";
ScreenWidth(Firefox1024,Firefox800,Firefox1152,Firefoxother)
}else{
//如果瀏覽器為其他
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;
}
//-->
</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文件名.
不判斷分辨率,只判斷瀏覽器
實現(xiàn)根據(jù)瀏覽器類型自動調(diào)用不同CSS。
復(fù)制代碼 代碼如下:
<SCRIPT LANGUAGE="JavaScript">
<!--
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;
}
//-->
</SCRIPT>
<!--
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;
}
//-->
</SCRIPT>
解釋:
如果瀏覽器為IE,則調(diào)用default.css
如果瀏覽器為Firefox,則調(diào)用default2.css
如果瀏覽器為其他,則調(diào)用newsky.css
用法:
放在
[codes=xml]</head>[/codes]
前面即可。
只判斷分辨率,不判斷瀏覽器
復(fù)制代碼 代碼如下:
<script language=javascript>
<!--
if (screen.width == 800)
{
document.write('<link rel=stylesheet type="text/css" href="css800.css">')
}
else {document.write('<link rel=stylesheet type="text/css" href="css1024.css">')}
//-->
</script>
<!--
if (screen.width == 800)
{
document.write('<link rel=stylesheet type="text/css" href="css800.css">')
}
else {document.write('<link rel=stylesheet type="text/css" href="css1024.css">')}
//-->
</script>
相關(guān)文章
開啟Javascript中apply、call、bind的用法之旅模式
在Javascript中,F(xiàn)unction是一種對象。Function對象中的this指向決定于函數(shù)被調(diào)用的方式,使用apply,call 與 bind 均可以改變函數(shù)對象中this的指向。2015-10-10JS實現(xiàn)點擊文字對應(yīng)DIV層不停閃動效果的方法
這篇文章主要介紹了JS實現(xiàn)點擊文字對應(yīng)DIV層不停閃動效果的方法,實例分析了javascript操作div層的效果,非常實用,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03showModalDialog 和 showModelessDialog
showModalDialog 和 showModelessDialog...2007-01-01