We can use following functions for adding the Javascript file dynamically.
01 | function AddJsFile(file) { |
02 | var script = document.createElement( 'script' ); |
04 | script.type = 'text/javascript' ; |
07 | document.getElementsByTagName( 'head' ).item(0).appendChild(script); |
10 | Or We can use this also, both will work: |
11 | function AddJsFile(file) |
We can use following functions for adding the CSS file dynamically.
1 | function AddCssFile(file) { |
2 | var stylesheet = document.createElement( 'link' ); |
4 | stylesheet.type = 'text/css' ; |
5 | stylesheet.defer = true ; |
7 | document.getElementsByTagName( 'head' ).item(0).appendChild(stylesheet); |
Or We can use this also, both will work:
1 | function AddCssFile(file) |
We can use the following code for remving the JS the files.
1 | function RemoveJsFile(file) { |
2 | var alljs = document.getElementsByTagName( "js" ) |
3 | for ( var i = alljs.length; i >= 0; i--) { |
4 | if (alljs[i] && alljs[i].getAttribute( "src" )!= null && alljs[i].getAttribute( "src" ).indexOf(file)!=-1) |
6 | alljs[i].parentNode.removeChild(alljs[i]) |
We can use the following code for remving the CSS the files.
1 | function RemoveCssFile(file) { |
2 | var allcss = document.getElementsByTagName( "css" ) |
3 | for ( var i = alljs.length; i >= 0; i--) { |
4 | if (allcss[i] && allcss[i].getAttribute( "href" )!= null && allcss[i].getAttribute( "href" ).indexOf(file)!=-1) |
6 | allcss[i].parentNode.removeChild(allcss[i]) |