Behaviour addLoadEvent()

Logo of Behavior JavaScript libraryI recently discovered that the Behaviour library contains an addLoadEvent() method allowing you to run code onLoad of the page. Before I found this, I was still including script in the body markup (the onload attribute of the body tag). Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<!doctype html public "-//w3c//dtd xhtml 1.1//en"
<html xmlns="" xml:lang="en" >
<script src="behaviour.js" type="text/javascript"></script>
<script type="text/javascript">
Behaviour.addLoadEvent(function(){alert("Hello, World!")});
This is the page body.

This method allows you to keep true to Behavior's purpose: to keep script out of your markup via unobtrusive JavaScript.


Post a Comment

Aaron Hursman
Aaron Hursman is a passionate user-advocate who is lucky enough to do what he loves for a living. As a user experience architect, he applies user-centered design principles and techniques including user research, persona development, information architecture, storyboards, wireframes, prototyping, visual design, graphic design, interaction design, and usability. Aaron has a background in web development, enterprise applications, and the social web. At nGame, he is applying his craft to design and build the next generation of enterprise software. Aaron is available as a speaker and author upon request.
Disclaimer: The information in this website is provided "as is" with no warranties, and confers no rights. This website does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my own personal opinion. Inappropriate comments will be deleted at the authors discretion. All instructions and code samples (if any, ever) are provided "as is" without warranty of any kind, either express or implied.