Using JavaScript Click Interceptions in an Image Gallery
If you’re a web developer with an intermediate level of experience building JavaScript applications, then you may have already used click interceptions in one form or another. Basically, as its name would suggest, this client-side method consists of “catching” a mouse click that occurs on a selected element of a web page to modify its default behavior. In this second part of a four-part series, you'll learn how to use click interceptions in an image gallery.
Using JavaScript Click Interceptions in an Image Gallery - Listing the full source code of the improved image gallery (Page 4 of 4 )
In consonance with the concepts I deployed in the section you just read, below I included the complete source code of this simple image gallery. As you saw before, it uses the click interception approach to improve its existing behavior.
Here's the corresponding code sample:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<h1>Example on building an image gallery using click interception</h1>
<div id="linkcontainer">
<ul>
<li><a href="sampleimagea.gif" title="First sample image goes here">View first image</a></li>
<li><a href="sampleimageb.gif" title="Second sample image goes here">View second image</a></li>
<li><a href="sampleimagec.gif" title="Third sample image goes here">View third image</a></li>
</ul>
</div>
<div id="imgcontainer"></div>
</body>
</html>
Feel free to use all of the code samples shown in this article to improve your JavaScript click interception skills.
Final thoughts
In this second installment of the series, you hopefully learned how to utilize click interceptions to extend the existing functionality of a primitive image gallery. This example demonstrates how useful this approach can be when used in a real-word situation.
In the next tutorial, I'm going to show you how to use click interceptions to improve the behavior of a database-driven web application. This topic will be very educational and give you some useful knowledge, so don't miss the next part!
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.