Take the 2-minute tour ×

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.

share|improve this question
You can overwrite console.log as suggested here –  A. Rodas Feb 17 '13 at 18:27
Won't that print the results in the iframe's content? I'd like to print the console logs in a div inside the iframe container's body –  Adonis K. Feb 17 '13 at 18:46
add comment

1 Answer

up vote 7 down vote accepted

If you want to print the log messages inside the window container's body, it is possible to declare the panel there:

var console = {
    panel: $(parent.document.body).append('<div>'),
    log: function(m){
share|improve this answer
Hi, thanks it works as expected but could you please explain what this line does? panel: $(parent.document.body).append('<div>'),, I don't understand why we use the .append('div') part. –  Adonis K. Feb 17 '13 at 23:01
That's only for wrapping the messages into a single div. You can use panel: $(parent.document.body) too, but then you'll have each message directly as a child of the container's body. –  A. Rodas Feb 17 '13 at 23:19
Ya after a while i understood its purpose and modified it to fit my needs, thanks for taking the time to explain it to me. –  Adonis K. Feb 18 '13 at 3:45
add comment

Your Answer


