Handling Event Handlers

by Nick Jensen on November 25, 2013

Those of you who have read my first JavaScript blog probably know that I am having trouble with a certain HTML file I set up months ago. I had just created my first web page and everything I put on it worked perfectly….except one video file. I wanted the video file to play ONLY when I clicked the mouse over it. Alas, I still haven’t fixed it. Now, I am reading John Pollock’s JavaScript: A Beginner’s Guide with the hopes of finding a solution to this conundrum. When I first read from that event handlers help web designers control how and when events occur in an HTML document, I grew excited. Finally, I thought, I can figure out how to stop that that cursed video file from playing until I say so. Unfortunately, I haven’t found any relevant information related to video files. The search must go on. For now, however, I would like to introduce you to event handlers; JavaScript codes which trigger certain actions based on user input. If you don’t follow what I’m getting at, don’t feel bad. I had a difficult time understanding event handlers as well.

Event handlers are basically JavaScript codes which are programmed to perform certain actions when triggered. For instance, an event handler can trigger a text box to appear when an external user drags his/her mouse over a link. An event handler can also be set to trigger after a page finishes loading. If I wanted you to go straight to the bottom of a web page as soon as it finished loading, I could program an event handler to trigger a popup box saying “If you are familiar with HTML then ignore all the junk at the top of the page and scroll to the bottom.”

<body onload=”window.alert (‘ If you are familiar with HTML then ignore all the junk at the top of the page and scroll to the bottom.’);”>

*Text between the top and bottom of page*

</body>

The key thing to remember about event handlers is that they can guide or even command users to a prescribed location within an HTML file. To give you a basic idea of what I mean, imagine a YouTube advertisement (you know, the ones you’re forced to sit through time after time). The ads are triggered to play as soon as the page finishes loading. In some cases (but not nearly enough), a message will appear when the ad starts to let you know you can skip the advertisement. Sometimes, you have to wait a few seconds before they let you click the skip button (It’s usually after the second they smear their logo all over the advertisement). While the ads may not be triggered by JavaScript, the principles behind both event handlers and Youtube advertisements remain the same.

Well, it looks like I’ll have to wait a little longer before I can find out how to stop that cursed video from playing automatically. Hopefully, you have learned some valuable information from this blog entry. Still, if you really want to learn the fundamentals of JavaScript, find a copy of

JavaScript: A Beginner’s Guide. It’s an acquired taste, but if you take your time while reading the book, you’ll find gain some very useful knowledge.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: