使用JavaScript檢測Firefox瀏覽器是否啟用了Firebug的代碼
更新時間:2010年12月28日 19:13:14 作者:
在啟用Firebug的情況下訪問GMail會收到一個 Firebug會讓Gmail變慢 的警告,這是如何檢測的呢?這里就說說。
在啟用了firebug面板后,會增加一個window.console對象及window.console.firebug變量用于保存當前firebug的當前版本,當關閉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中也能正常輸出調試信息。
復制代碼 代碼如下:
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中也能正常輸出調試信息。
相關文章
淺談webpack打包生成的bundle.js文件過大的問題
下面小編就為大家分享一篇淺談webpack打包生成的bundle.js文件過大的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02
js屏蔽鼠標鍵盤(右鍵/Ctrl+N/Shift+F10/F11/F5刷新/退格鍵)
屏蔽鼠標右鍵、Ctrl+N、Shift+F10、F11、F5刷新、退格鍵/Alt+ 方向鍵 →等等,太多了就不一一寫來了感興趣的朋友可以了解下啊,希望本文對你有所幫助2013-01-01
JavaScript中net::ERR_CONNECTION_REFUSED解決方法大全
在一次測試中遇到了報net::ERR_CONNECTION_REFUSED的錯誤,五哦一下面這篇文章主要給大家介紹了關于JavaScript中net::ERR_CONNECTION_REFUSED解決方法的相關資料,需要的朋友可以參考下2022-10-10

