Created
January 1, 2016 22:44
-
-
Save stvrbbns/9e87e71f4f09734d0eef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** includeJS() appends a JavaScript file to an element of the open document. | |
* @param jsPath -- string - the path to the JavaScript file. | |
* @param docLocName -- string - optional - element tag or ID name; | |
* defaults to "head". | |
* @param docLocType -- string - optional - type of element name, "tag" or "id"; | |
* defaults to "tag". | |
* @param docLocNum -- integer - optional - number of element with tag name; | |
* defaults to 0. | |
*/ | |
function includeJS(jsPath, docLocName, docLocType, docLocNum) | |
{ | |
// Set default values. | |
if(docLocName == null) { docLocName = 'head'; } | |
if(docLocType == null) { docLocType = 'tag'; } | |
if(docLocNum == null) { docLocNum = 0; } | |
// Prepare the JavaScript document. | |
var js = document.createElement('script'); | |
js.setAttribute('type', 'text/javascript'); | |
js.setAttribute('src', jsPath); | |
// Append the JavaScript document to the appropriate document location. | |
if(docLocType == 'tag') | |
{ | |
document.getElementsByTagName(docLocName)[docLocNum].appendChild(js); | |
} else if(docLocType == 'id') | |
{ | |
document.getElementsById(docLocName).appendChild(js); | |
} | |
} // end of includeJS() function. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment