Function loadjscssfile (filename, filetype ){
If (filetype = "JS") {// determine the file type
VaR fileref = Document. createelement ('script') // create a tag
Fileref. setattribute ("type", "text/JavaScript") // defines the attribute type value as text/JavaScript
Fileref. setattribute ("src", filename) // file address
}
Else if (filetype = "CSS") {// determine the file type
VaR fileref = Document. createelement ("Link ")
Fileref. setattribute ("rel", "stylesheet ")
Fileref. setattribute ("type", "text/CSS ")
Fileref. setattribute ("href", filename)
}
If (typeof fileref! = "Undefined ")
Document. getelementsbytagname ("head") [0]. appendchild (fileref)
}
Loadjscssfile ("myscript. js", "JS") // when the page is opened, the browser dynamically loads the file
Loadjscssfile ("javascript. php", "JS") // when the page is opened, the browser dynamically loads "javascript. php ",
Loadjscssfile ("mystyle.css", "CSS") // the browser's dynamic .css file when opening a page
VaR filesadded = "" // Save the array variable of the name of the bound File
Function checkloadjscssfile (filename, filetype ){
If (filesadded. indexof ("[" + filename + "]") =-1) {// indexof checks whether an item exists in the array.
Loadjscssfile (filename, filetype)
Filesadded + = "[" + filename + "]" // Add the file name to filesadded
}
Else
Alert ("file already added! ") // Prompt if it already exists
}
Checkloadjscssfile ("myscript. js", "JS") // success
Checkloadjscssfile ("myscript. js", "JS") // redundant file, so file not added