DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 使用JavaScript檢測Firefox浏覽器是否啟用了Firebug的代碼
使用JavaScript檢測Firefox浏覽器是否啟用了Firebug的代碼
編輯:關於JavaScript     
在啟用了firebug面板後,會增加一個window.console對象及window.console.firebug變量用於保存當前firebug的當前版本,當關閉firebug面板後則變回正常,於是我們可以通過判斷其是否存在來檢測是否開啟了firebug。
復制代碼 代碼如下:
Boolean(window.console && window.console.firebug)

於是,為了方便在沒有啟用firebug的情況下避免腳本錯誤,可以在腳本最前面加入以下語句手工創建空的console對象以作兼容。
復制代碼 代碼如下:
if (!window.console) {
// ignore firebug console call if it's not installed
// for firebug 1.6.0
(function(m, i) {
window.console = {};
while (i--) {
window.console[m[i]] = function() {};
}
})('log debug info warn exception assert dir dirxml trace group groupEnd groupCollapsed time timeEnd profile profileEnd count clear table error notifyFirebug'.split(' '), 22);
}

這樣,在IE下能正常預覽頁面,在Firefox、Chrome、Safari中也能正常輸出調試信息。
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved