Ответ 1
Вот еще одно решение, если вы не хотите добавлять в HTML
var console = {
__on : {},
addEventListener : function (name, callback) {
this.__on[name] = (this.__on[name] || []).concat(callback);
return this;
},
dispatchEvent : function (name, value) {
this.__on[name] = (this.__on[name] || []);
for (var i = 0, n = this.__on[name].length; i < n; i++) {
this.__on[name][i].call(this, value);
}
return this;
},
log: function () {
var a = [];
// For V8 optimization
for (var i = 0, n = arguments.length; i < n; i++) {
a.push(arguments[i]);
}
this.dispatchEvent("log", a);
}
};
Вне iframe
iframe.contentWindow.console.addEventListener("log", function (value) {
console.log.apply(null, value);
});