Skip to content

Instantly share code, notes, and snippets.

@AMHOL
Last active December 17, 2015 05:08
Show Gist options
  • Save AMHOL/5555467 to your computer and use it in GitHub Desktop.
Save AMHOL/5555467 to your computer and use it in GitHub Desktop.
Windows phone console
if ( (typeof window.console == 'undefined' || typeof window.console.log != 'function') && !!window.location.href.match(/\?console=true/i) ) {
var ul = _createTag('ul', false, {
'line-height': '30px',
'background-color': '#fff',
'list-style-type': 'square',
color: '#000',
position: 'absolute',
top: 0,
right: 0,
left: 0,
'z-index': 9999
});
ul.appendChild(_createTag('li', {
innerText: 'Javascript Console'
}, {
'font-weight': 'bold',
display: 'block'
}));
window.console = {
log: function(logStr) {
ul.appendChild(_createTag('li', {
innerText: logStr.toString()
}));
}
};
function _createTag(nodeType, attributes, style) {
var elem = document.createElement(nodeType);
if ( typeof attributes != 'undefined' && attributes ) {
for ( var key in attributes ) {
elem[key] = attributes[key];
}
}
if ( typeof style != 'undefined' && style ) {
for ( var key in style ) {
elem.style[key] = style[key];
}
}
return elem;
};
var eventListener = (function() {
if ( typeof window.addEventListener != 'undefined' ) {
return 'addEventListener';
} else if ( typeof window.attachEvent != 'undefined' ) {
return 'attachEvent';
}
})();
window[eventListener]('load', function() {
document.body.appendChild(ul);
});
window.onerror = function(msg, url, line) {
console.log('Error: '+ msg +' on line: '+ line + ' in ' + url);
return true;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment