I'm working on an
online IDE (similar to jsFiddle, codepen, jsbin etc) and there is an issue I can't solve by myself.
Code:
var console={
panel : $(parent.document.body),
log : function(m){
this.panel.find("#target").append("<p>>" + m + "</p>");
}
};
I have JQuery code above which basically re-implements the console object so instead of printing the results in the JavaScript console to output the string in the iframe parent's div.
I tried converting it myself but I failed.
Code:
var console = {
panel : parent.document.body,
log : function(m) {
this.panel.getElementById("target").appendChild(document.createElement("p")); // trying to create a "p" element fails
};
};
It fails and returns this error:
Quote:
|
Uncaught TypeError: Object [object HTMLBodyElement] has no method 'getElementById'
|
Can someone help me fix this?
edit:
I just tried to manually run this:
Code:
parent.document.getElementById("target").appendChild(document.createElement("p"));
edit#2:
Nvm, I managed to fix it by doing this:
Code:
var console = {};
console.log = function(m) {
parent.document.getElementById("target").insertAdjacentHTML("beforeend", "<p>> " + m + "</p>");
};