Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function import(url) {
- var ext = url.match(/\.([a-z]+)$/)[1];
- if (ext === 'js') {
- var s = document.createElement('script');
- s.setAttribute('src', url);
- document.body.appendChild(s);
- } else if (ext === 'css') {
- var s = document.createElement('link');
- s.setAttribute('rel', 'stylesheet');
- s.setAttribute('href', url);
- document.body.appendChild(s);
- } else {
- throw new TypeError('Can\'t import file with extension ' + '. Only CSS and JavaScript files can be imported.');
- }
- }
Add Comment
Please, Sign In to add comment