Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Last active August 29, 2015 13:56
Show Gist options
  • Save netsi1964/8864733 to your computer and use it in GitHub Desktop.
Save netsi1964/8864733 to your computer and use it in GitHub Desktop.
Generate window.console polyfill

This gist creates a simpel Console polyfill piece of code to add to projects where IE8 will visit your site. It will create a simple console object on window object avoiding any forgotten console.log for instance. It should be run on a browser which supports console object, say in the developer toolbar. It wil then generate a line of javascript code for you to paste into the website.

if (typeof window.console==='undefined') window.console = {'ver':'Fri Feb 07 2014 16:44:36 GMT+0100 (CET)','debug':function(){},'error':function(){},'info':function(){},'log':function(){},'warn':function(){},'dir':function(){},'dirxml':function(){},'table':function(){},'trace':function(){},'assert':function(){},'count':function(){},'markTimeline':function(){},'profile':function(){},'profileEnd':function(){},'time':function(){},'timeEnd':function(){},'timeStamp':function(){},'timeline':function(){},'timelineEnd':function(){},'group':function(){},'groupCollapsed':function(){},'groupEnd':function(){},'clear':function(){}}
var s = "if (typeof window.console==='undefined') window.console = {'ver':'"+new Date().toString()+"'";
for(a in console) {
var v=console[a];
if (typeof v==="function") {
s+=",'"+a+"':function(){}";
}
};
s+="}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment