I was wearing my DHTML hat the other day and wanted to share this javascript quick tip. When I have to script DOM objects but don’t have time to figure out their goings on, I like to dump them via a for() loop. Here’s how it works.
In my html file I’ll create this small script.
<script type="text/javascript">
function dump( objId )
{
var domObj = document.getElementById( objId );
// message holder
var str = "";
// loop
for( xx in domObj )
{
// append to the message
str += xx + " : " + domObj[ xx ] + "\n\n";
// how long is the message?
if( str.length >= 300 )
{
// show it
alert( str );
// reset it
str = "";
}
}
}
</script>
Next I’ll drop an html button into my page that passes the id of my desired object to the dump.
<button onClick="dump('parentform')">dump</button>
Lastly I’ll fire up my html file, click the dump button, and hope I find what I’m looking for in the alert.

dump popup
I don’t always find what I’m looking for, but I always end up finding interesting stuff. Especially when you run the same html file in different browsers. I wrote a similar javascript dumper that writes to the page instead of an alert. This one is also interesting to see in different browsers.
Tags: dom, enumerate, foreach, html, javascript
Posted in browser, javascript, tips and tricks | No Comments »
Nobody seems to talk about favicons these days. People still use them, but it’s rarely a topic of conversation. So we all know favicons show up in your browser’s address bar next to the url. If your website doesn’t have a favicon.ico file, then your browser will use a generic webpage icon.
The favicon also comes into play if you bookmark a webpage. The custom icon will appear in your bookmarks list, or on your desktop if you drag a page there. This is what the favicon is all about.
Tonight it dawned on me that any program that create ‘applications’ out of webpages, also use that favicon file as your desktop icon. In this case I’m using Google’s web browser Chrome to create an ‘application shortcut’. The application shortcut that Chrome creates is essentially a chromeless browser that goes directly to the url you specified. When this shortcut is created on your machine it uses that site’s favicon.ico if one exists.
So there you go. One more reason why you should always have a custom favicon.ico for any webpage you are in charge of.
-
-
Chrome create app.shortcut
-
-
Favicons in action
Tags: application shortcut, bookmark, chrome, favicon, web tip, webpage shortcut
Posted in browser, tips and tricks, web2.0 | No Comments »