Skip to content

Instantly share code, notes, and snippets.

@simondell
Created October 26, 2012 14:18
Show Gist options
  • Save simondell/3959080 to your computer and use it in GitHub Desktop.
Save simondell/3959080 to your computer and use it in GitHub Desktop.
A function for displaying debug messages in environments where console.log support is feeble (like pre-iOS6 Mobile Safari)
function debug(msg) {
var container = document.getElementsByTagName('body')[0],
bug = document.createElement('div'),
bugStyle = bug.style,
bugSplat;
console.log('msg');
bugStyle.position = 'absolute';
bugStyle.top = '50%';
bugStyle.left = '20px';
bugStyle.width = '260px';
bugStyle.height = '100px';
bugStyle.border = '1px solid white';
bugStyle.marginTop = '-50px';
bugStyle.zIndex = '200';
bugStyle.backgroundColor = '#eaeaea';
bugStyle.color = '#333';
bugStyle.webkitBoxShadow = '0px 3px 5px 3px rgba(25,25,25,0.4)';
bugStyle.webkitBorderRadius = '5px';
bugStyle.padding = '10px';
bugStyle.font = 'normal 16px/20px "Helvetica Neue", Arial';
bug.addEventListener('click', bugSplat = function () {
bug.removeEventListener('click', bugSplat);
container.removeChild(bug);
}, false);
setTimeout(function () {
bug.removeEventListener('click', bugSplat);
container.removeChild(bug);
}.bind(bug), 1500);
bug.innerText = msg;
container.appendChild(bug);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment