经常做一些政府机构网站开发,他们经常是内网环境下,而且大部分是window7系统,浏览器大部分是IE7或IE8,这样子就可能在开发网站的时候,忘记删除输出日志代码,打开页面就会报错。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>console</title>
</head>
<body>
<script>
var _console = (function () {
//判断是否存在console对象
if (window.console){
return window.console;
}
var _console = {};
_console.memory = {
jsHeapSizeLimit: 3760000000,
totalJSHeapSize: 10000000,
usedJSHeapSize: 10000000
};
_console.assert = function (msg) {};
_console.clear = function () {};
_console.count = function (msg) {};
_console.debug = function (msg) {};
_console.dir = function (msg) {};
_console.dirxml = function (msg) {};
_console.error = function (msg) {};
_console.exception = function (msg) {};
_console.group = function (msg) {};
_console.groupCollapsed = function (msg) {};
_console.groupEnd = function (msg) {};
_console.info = function (msg) {};
_console.log = function (msg) {};
_console.markTimeline = function (msg) {};
_console.profile = function (msg) {};
_console.profileEnd = function (msg) {};
_console.table = function (msg) {};
_console.time = function (msg) {};
_console.timeEnd = function (msg) {};
_console.timeStamp = function (msg) {};
_console.timeline = function (msg) {};
_console.timelineEnd = function (msg) {};
_console.trace = function (msg) {};
_console.warn = function (msg) {};
_console.test = function (msg) {};
return _console;
})(window);
window.console = _console;
window.onload = function () {
console.log(console);
}
</script>
</body>
</html>