Created
April 19, 2016 16:18
-
-
Save seayxu/67877df8fdc80425e0396557567edab3 to your computer and use it in GitHub Desktop.
dynamic load css and javascript file
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
//dynamic load css file | |
function loadcss(path){ | |
if(!path || path.length === 0){ | |
throw new Error('argument "path" is required !'); | |
} | |
var head = document.getElementsByTagName('head')[0]; | |
var link = document.createElement('link'); | |
link.href = path; | |
link.rel = 'stylesheet'; | |
link.type = 'text/css'; | |
head.appendChild(link); | |
} | |
//dynamic load javascript file | |
function loadjs(path){ | |
if(!path || path.length === 0){ | |
throw new Error('argument "path" is required !'); | |
} | |
var head = document.getElementsByTagName('head')[0]; | |
var script = document.createElement('script'); | |
script.src = path; | |
script.type = 'text/javascript'; | |
head.appendChild(script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment