使用JavaScript檢測Firefox瀏覽器是否啟用了Firebug的代碼
更新時間:2010年12月28日 19:13:14 作者:
在啟用Firebug的情況下訪問GMail會收到一個 Firebug會讓Gmail變慢 的警告,這是如何檢測的呢?這里就說說。
在啟用了firebug面板后,會增加一個window.console對象及window.console.firebug變量用于保存當前firebug的當前版本,當關(guān)閉firebug面板后則變回正常,于是我們可以通過判斷其是否存在來檢測是否開啟了firebug。
Boolean(window.console && window.console.firebug)
于是,為了方便在沒有啟用firebug的情況下避免腳本錯誤,可以在腳本最前面加入以下語句手工創(chuàng)建空的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中也能正常輸出調(diào)試信息。
復制代碼 代碼如下:
Boolean(window.console && window.console.firebug)
于是,為了方便在沒有啟用firebug的情況下避免腳本錯誤,可以在腳本最前面加入以下語句手工創(chuàng)建空的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中也能正常輸出調(diào)試信息。
您可能感興趣的文章: