欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用Javascript判斷操作系統(tǒng)的類型實(shí)現(xiàn)不同操作系統(tǒng)下的兼容性

 更新時(shí)間:2013年01月29日 11:22:21   作者:  
在通過(guò)Javascript實(shí)現(xiàn)客戶端和服務(wù)端的交互時(shí),有時(shí)候需要對(duì)操作系統(tǒng)進(jìn)行判斷,以便實(shí)現(xiàn)不同操作系統(tǒng)下的兼容性;從而實(shí)現(xiàn)網(wǎng)站在跨平臺(tái)瀏覽時(shí)候保持良好的用戶體驗(yàn),感興趣的朋友可以了解下啊,或許對(duì)你有所幫助
在通過(guò)Javascript實(shí)現(xiàn)客戶端和服務(wù)端的交互時(shí),有時(shí)候需要對(duì)操作系統(tǒng)進(jìn)行判斷,以便實(shí)現(xiàn)不同操作系統(tǒng)下的兼容性,比如:我們有一個(gè)網(wǎng)站, 在Windows XP下瀏覽效果良好,但是到了Ubuntu下,由于許多特性不同,會(huì)造成在瀏覽上的細(xì)微差異,甚至?xí)绊懙搅己玫挠脩趔w驗(yàn)。這個(gè)時(shí)候我們就需要利用 Javascript對(duì)操作系統(tǒng)的類型以及某些特性進(jìn)行判斷,分而治之,從而實(shí)現(xiàn)網(wǎng)站在跨平臺(tái)瀏覽時(shí)候保持良好的用戶體驗(yàn)。
下邊的代碼實(shí)現(xiàn)對(duì)Windows、Mac、Linux、Unix擦作系統(tǒng)的判斷:
復(fù)制代碼 代碼如下:

<script type="text/javascript" language="JavaScript">
<!--
function check_os() {
windows = (navigator.userAgent.indexOf("Windows",0) != -1)?1:0;
mac = (navigator.userAgent.indexOf("mac",0) != -1)?1:0;
linux = (navigator.userAgent.indexOf("Linux",0) != -1)?1:0;
unix = (navigator.userAgent.indexOf("X11",0) != -1)?1:0;
if (windows) os_type = "MS Windows";
else if (mac) os_type = "Apple mac";
else if (linux) os_type = "Lunix";
else if (unix) os_type = "Unix";
return os_type;
}
//-->
</script>

如果我們需要對(duì)Windows操作系統(tǒng)進(jìn)行更為精確的識(shí)別,可以繼續(xù)使用下邊的代碼操作:
復(fù)制代碼 代碼如下:

<script type="text/javascript" language="JavaScript">
<!--
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows"); // 確保為windows系統(tǒng)
var isWin98 = isWin2000 = isWinXP = false;
var sUserAgent = navigator.userAgent;
if(isWin) {
isWin98=sUserAgent.indexOf("Win98") > -1 || sUserAgent.indexOf("Windows 98") > -1; // win98
isWin2000=sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1; //win2000
isWinXP=sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows Xp") > -1; //winxp
isWin98 && alert("window 98");
isWin2000 && alert("windows 2000");
isWinXP && alert("windows XP");
}
//-->
</script>

下邊的代碼是為了實(shí)現(xiàn)對(duì)瀏覽器是否支持XML特性的檢測(cè):
復(fù)制代碼 代碼如下:

<script type="text/javascript" language="JavaScript">
var SupportXml=false;
var xmldom;
if(window.ActiveXObject) {
try {
xmldom=new ActiveXObject("Microsoft.XMLDOM");
SupportXml=(xmldom.loadXML(" <ok/>"));
} catch(e) {}
}
else if(document.implementation && document.implementation.createDocument) {
SupportXml=true;
}
alert('XML狀態(tài)為:'+SupportXml);
</script>

PS:為了更好地避免不同瀏覽器,不同操作系統(tǒng)因?yàn)槟J(rèn)文字不同而對(duì)頁(yè)面布局造成影響,應(yīng)盡量避免CSS中使用固定行高(height:12px;)對(duì) 文字高度進(jìn)行限定,應(yīng)該盡量使用height:auto,如果迫不得已必須限定文字高度(比如只顯示一行),則應(yīng)使用em代替px(例如 height:1.1em;),1em=1文字高度,這樣就使得文字高度隨著文字大小動(dòng)態(tài)改變,不會(huì)造成文字截?cái)喱F(xiàn)象的發(fā)生了。

相關(guān)文章

最新評(píng)論