你目前所使用的流覽器的資料:
var userAgent = navigator.userAgent.toLowerCase();
var browser =
(browser = userAgent.match(/qqbrowser/([d.]+)/))?"qqbrowser/"+browser[1]:
(browser = userAgent.match(/ses+2.x/))?"sogou/2.x": //sougou
(browser = userAgent.match(/msies+([d.]+)/))?"msie/"+browser[1]: //ie
(browser = userAgent.match(/chrome/([d.]+)/))?"chrome/"+browser[1]: //chrome
(browser = userAgent.match(/firefox/([d.]+)/))?"firefox/"+browser[1]: //firefox
(browser = userAgent.match(/version/([d.]+)s+safari/([d.]+)/))?"safari/"+browser[1]: //safari
(browser = userAgent.match(/opera/([d.]+)([wW]+)version/([d.]+)/))?"opera/"+browser[3]: //opera
"other browser";
//以上是條件運算子“?:"的嵌套使用
var browser4 = browser.substr(0,6);
document.write("
" + "Browser:" + " | ");" + browser4 + " |
" + "Browser Version:" + " | ");" + browser + " |
" + "userAgent:" + " | ");" + userAgent + " |
" + "appVersion:" + " | ");" + appVersion + " |
" + "appCodeName:" + " | ");" + appCodeName + " |
" + "appName:" + " | ");" + appName + " |
" + "platform:" + " | ");" + platform + " |
使用chrome顯示網頁內容如下:
使用firefox顯示網頁內容如下:
2 JS獲取視窗資料
流覽器視窗資料:
右邊的資料反映流覽器視窗高寬的資料(單位是px,不包括上端的功能表列和工具列, 也不包括下端的狀態列;按F11全屏顯示或“還原”按鈕並調整大小也會有不同的資料回饋。 ) |
var winWidth = 0;
var winHeight = 0;
function findDimensions() //函數:獲取尺寸
{
//獲取視窗寬度
if (window.innerWidth)
winWidth = window.innerWidth;
else if ((document.body) && (document.body.clientWidth))
winWidth = document.body.clientWidth;
//獲取窗口高度
if (window.innerHeight)
winHeight = window.innerHeight;
else if ((document.body) && (document.body.clientHeight))
winHeight = document.body.clientHeight;
//通過深入Document內部對body進行檢測,
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
{
winHeight = document.documentElement.clientHeight;
winWidth = document.documentElement.clientWidth;
}
//結果輸出至兩個文字方塊
document.form1.availHeight.value= winHeight;
document.form1.availWidth.value= winWidth;
}
findDimensions();
//調用函數, 獲取數值
window.onresize=findDimensions;
使用chrome顯示網頁內容如下:
使用firefox顯示網頁內容如下:
-End-