A Modular Toolbox

Submitted by:Andery Smith

Date added:13 November, 2012


Creating and maintaining an effective JavaScript toolbox can greatly reduce development time. This script will show you how to include specific snippet modules on individual pages.

Tags: toolbox

Code Snippet:

# Paste this code into an external JavaScript file named: modules_control.js

/* Created by: Anthony Corbelli | http://www.htmlgoodies.com/ */

// This function returns a collection of elements, an array of 1 is still an array.
var cHead = document.getElementsByTagName("head");

// Select the first element (remember, indexed arrays start at 0 not 1).
var hHead = cHead[0];

// Takes the Javascript file name and adds it to the document as a script
function AddModule(mFileName) {
var sTag = document.createElement("script"); // Create a SCRIPT tag
sTag.setAttribute("src", mFileName); // Set the SCRIPT src=mFileName
sTag.setAttribute("type", "text/javascript"); // set the SCRIPT type="text/javascript"
hHead.appendChild(sTag); // Add it to your header section (parsed and run immediately)


# Paste this code into the HEAD section of your HTML document.

<script type="text/javascript" src="modules_control.js"></script>

<script type="text/javascript">