簡單的檢查瀏覽器 JS


由於今天晚上試了一下用 iframe 的方法來模擬框架,在寫入資料時為了解決 document.write 的問題,所以就分開了 IE 和 FF 的寫法,方便之後對傳送資料的處理 ..@@ 函數如下 :

1
2
3
4
5
6
7
8
function checkBrowser(os) {
b_arr = { 'FF':'gecko', 'IE':'msie', 'OP':'opera' }
return navigator.userAgent.toLowerCase().indexOf(b_arr[os]) != -1 ? true : false;
}

alert(checkBrowser('FF')); // 檢查 FireFox
alert(checkBrowser('IE')); // 檢查 Internet Explorer
alert(checkBrowser('OP')); // 檢查 Opera