Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active December 10, 2015 23:08
Show Gist options
  • Save twolfson/4507198 to your computer and use it in GitHub Desktop.
Save twolfson/4507198 to your computer and use it in GitHub Desktop.
Quick console for debugging inside of IE7 VM
function Console() {
// Create a div and textarea for the console
var div = document.createElement('div'),
output = document.createElement('div'),
textarea = document.createElement('textarea'),
button = document.createElement('button'),
that = this;
// Style the div
div.style.cssText = 'position: fixed; top: 0; left: 0; background: white; border: 1px solid black; z-index: 10000;';
// Notify the user this is an eval button
button.innerHTML = 'Eval';
// When the button is pressed, run eval
button.onclick = function () {
that.eval(that.textarea.value);
};
// Append the elements to div
div.appendChild(output);
div.appendChild(textarea);
div.appendChild(button);
// Save the elements for later
this.div = div;
this.output = output;
this.textarea = textarea;
this.button = button;
}
Console.prototype = {
// Low-level writer to console
'write': function (str) {
this.output.innerHTML += str;
},
// Interacts like console.log
'log': function () {
// Iterate over the arguments
var i = 0,
len = arguments.length;
for (; i < len; i++) {
// Log the argument
this.write(arguments[i] + '<br/>');
}
},
// Eval for running your code
'eval': window.eval
};
// Create a new console
var console = new Console();
// When the DOM is loaded, append the console to the body
window.onload = function () {
document.body.appendChild(console.div);
};
// Save the console to window
window.console = console;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment