Sunday, August 07, 2005

Know thy Javascript.

Ok, Javascript & Ajax seem to be taking a beating lately. Lets kick out a couple pointers so people feel more comfortable with it:

element.setAttribute("attr_name", attr_value);
elemenet.getAttribute("attr_name");

The above works in Safari, Firefox, Konquerer, IE, you name it. Don't be tempted by element indexers, named attributes, etc. setAttribute() & getAttribute() are the only ones you should use.

timeout = window.setTimeout(function() { alert("Test!"); }, 5000, "javascript");
window.setTimeout(function() { window.clearTimeout(timeout); }, 2500, "javascript");

This is how you cancel something. If you're going to popup a window with a timer for example on an element mouseover, make sure you cancel it appropriately. Don't let events just chain so your popup's contents flash through 5 different elements before getting to the current one. Cancel the previous timer when mousing over a different element.
Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?