Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  67] [ 2]  / answers: 1 / hits: 35074  / 12 Years ago, sun, february 17, 2013, 12:00:00

Is there a way to capture the console outside of an iframe?



I'm working on an online IDE similar to jsFiddle and I wanted to give the users to option to at least read the results of the javascript console.


More From » iframe

 Answers
8

Here is another solution if you don't want to append to 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);
}
};


Outside the iframe



iframe.contentWindow.console.addEventListener(log, function (value) {
console.log.apply(null, value);
});

[#80172] Friday, February 15, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tobyl

Total Points: 598
Total Questions: 110
Total Answers: 114

Location: Vietnam
Member since Sat, Feb 12, 2022
2 Years ago
tobyl questions
Tue, Aug 10, 21, 00:00, 3 Years ago
Wed, Jan 13, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
;