Skip to content

Instantly share code, notes, and snippets.

@napcs
Created June 2, 2013 19:12
Show Gist options
  • Save napcs/5694538 to your computer and use it in GitHub Desktop.
Save napcs/5694538 to your computer and use it in GitHub Desktop.
Sometimes I need a way to view messages easily on devices where the console doesn't work. So I use this. It's a little crude but it works really well on tablets and phones when I need to watch events.
/**
@method __message
@param text {string} The text you want to display
@param [append=null] {boolean} Whether the message should append to the box or not.
@example
$("a").on("click", function(event){
window.__message("You clicked a thing!");
});
*/
window.__message = function(text, append){
id = "__messagearea"
var area = document.getElementById(id);
if(!area){
area = document.createElement("div");
area.id = id;
body = document.getElementsByTagName("body")[0];
body.insertBefore(area, body.firstChild);
area.style.height = "50px";
area.style.overflow = "scroll";
area.style.position = "relative";
area.style.border = "1px solid #ddd";
}
if(append){
area.innerHTML = text + "<br>" + area.innerHTML;
}else{
area.innerHTML = text;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment