Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A tool for getting at a JS console when there is none available.
<div id="consolelog" style="font-family: 'Courier New', Courier, monospace; font-size: 12px; margin: 40px 30px 0px; background-color: white; border: 2px solid black; padding: 10px;"></div>
<input type="text" id="consoleinput" style="margin: 0px 30px; width: 400px;" onkeypress="return evalConsoleInput(event, this.value);" />
<script type="text/javascript">
var appendConsole = function(message, type) {
var color = "black";
if (type === "error") {
color = "red";
} else if (type === "debug") {
color = "blue";
var div = document.createElement('div'); = color; = "10px";
div.innerHTML = message;
var originalConsole = null;
if (window.console != null) {
originalConsole = window.console;
window.console = {
log: function(message) {
appendConsole(message, "info");
info: function(message) {
appendConsole(message, "info");;
debug: function(message) {
appendConsole(message, "debug");
error: function(message) {
appendConsole(message, "error");
function evalConsoleInput(e, message)
if (e.keyCode == 13) { // 13 is the keycode for the enter key
var inputField = document.getElementById("consoleinput");
var evalString = inputField.value;
console.log("> " + evalString);
try {
var returnValue = eval(evalString);
} catch (e) {
} finally {
inputField.value = "";

This comment has been minimized.

Copy link

@danharper danharper commented Feb 28, 2014

Had you considered using Weinre for remote debugging? I've been using this for debugging PhoneGap applications whilst they're running natively on a device.


This comment has been minimized.

Copy link
Owner Author

@ejdyksen ejdyksen commented Mar 2, 2014

@danharper I would have loved to use something more sophisticated, but I didn't have network access to the browser session at all from my development machine (odd as that seems).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.