Category: Web Development


Another Simple console.log wrapper – debug log for all browsers

February 18th, 2012 — 9:22pm

Issues:

1. You can add console.log all day long but at the end of the day you have to remove them.

2. When testing on IE, you got to comment out or remove console.log otherwise it will error out.

3. for IE, you might end up adding Alert(msg). Clicking Alert could become painful.

Solution (might not be the best but works):

So I wrote Another simple console.log wrapper that meets what I need for now (super super simple)

Out put on IE would look like this:

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<title>Fun with Debugging</title>
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>
<style type=”text/css”>
.console{
font-family:monospace;
font-size:12px;
color:white;
background-color:black;
padding: 0 0 0 10px;
}
</style>
</head>
<body class=’body’>
<h1>Header</h1>
<p>contents here</p>
</body>
<script>
var debug = {
debug: false,
log: function(msg){
if (this.debug){
if(window.console){
console.log(msg)
}else{
$(‘body’).append(‘<div class=”console”>’ + msg + ‘</div>’);
}
}
},
enable: function(){this.debug = true},
disable: function(){this.debug = false}
}

debug.enable(); // remove or comment out before send to prod or just remove all debug. line with grep or something
debug.log(‘ahoy’);
debug.log(‘more message’);
// debug.disabled();
debug.log(‘debug is disabled now’);
</script>
</html>

Comment » | HTML, JavaScript, Web Development

Know how to use Chrome developer tools I – Disable Cache

January 29th, 2012 — 2:50pm

1. Open Web Developer Tools
(Option + Command + i) or (Menu > View > Developer > Developer Tools

 

 

 

 

2. Disable Cache

2.1. Go to Settings

2.1.1. Click Gear icon on lower bottom

2.1.2. Check Disable Cache

 

Comment » | HTML, JavaScript, mac, OS X, Web Development

Back to top