Silencing (or somehow overriding) iframe console when its src attribute is changed via code

Viewed 70

I've been struggling with this issue for a few days now, but with almost no success. I'm going to silence (or in fact override) iframe console contents. Following line of code works fine as long as iframe content is added (i.e. via contentWindow.document.write(....) ):

iframe.contentWindow.console.log = function(a) { alert(a) /* nop */ };

But my iframe will have its src attribute changed, and it seems that as soon as src attribute is changed, contentWindow (and all its properties, including console) are overwritten to the default values.

I've already tested several ways and know that this question has been answered before (here for instance: http://jsfiddle.net/gskf2dxx/18/) but even the same code doesn't work for me.

I've even tried overriding console.log in iframe.onload event, but onload event is somehow too late, it is triggered just when the page is fully loaded and therefore any console.log existing in the iframe src have been printed onto the browser console.

0 Answers
Related