Reputation: 1133
We are displaying Google Adwords ads on our site. Something that irriates me to no end is that the ads will run with errors or normal console.log() output and that text appears in our console. I am wondering if there is anyway to turn these errors off through Adword's scripting, or through Javascript.
Ads appear in an iframe.
Upvotes: 2
Views: 126
Reputation: 1134
You can re-define the console.log output as such:
var oldConsole = console;
console = {
log: function(str,goOut = false) {
if (goOut) {
oldConsole.log(str);
}
},
warn: function(str,goOut = false) {
if (goOut) {
oldConsole.warn(str);
}
},
error: function(str,goOut = false) {
if (goOut) {
oldConsole.error(str);
}
}
}
console.log("this will not appear");
console.log("This will appear",true);
Saving the console object to oldConsole allows you to still actually output to the console, then re-defining the console object allows you to change the function.
With this function, to actually output something, you need to put TRUE as the second parameter, which is not done by default, to all of your console.log output so that it actually appears.
As a note, here's exactly what's happening:
Upvotes: 2