Fogeaters, Light The World.

20

2017-Sep

[javascript] js, css 파일 동적 로딩

작성자: title: MoonBlonix IP ADRESS: *.64.228.3 조회 수: 1396

출처 :: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function loadjscssfile(filename, filetype){
    if (filetype=="js"){ //if filename is a external JavaScript file
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        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") //dynamically load and add this .js file
loadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a JavaScript file
loadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file
profile
List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 [Web] 클라우드 IDE + 2 title: MoonBlonix 2017-06-25 15118
132 [vsftpd] root(루트) 접속 title: MoonBlonix 2018-04-15 1731
131 [php] 모바일 인식 title: MoonBlonix 2018-03-19 1362
130 [nginx] php 502 Bad Gateway 에러 해결 title: MoonBlonix 2018-03-19 1414
129 라즈베리파이를 위한 nginx와 php7.0 저장소 title: MoonBlonix 2018-02-24 1468
128 [javascript] Date사용 및 날자 계산 title: MoonBlonix 2017-12-29 1617
127 [php] 달력 구현 소스 + 1 title: MoonBlonix 2017-12-25 1857
126 [javascript] 팝업 열기 title: MoonBlonix 2017-12-18 1726
125 [php] 날짜/시간 함수정리 title: MoonBlonix 2017-12-09 1581
124 [mysql] 조건문 사용 (if, case), (isnull, ifnull, nvl) title: MoonBlonix 2017-12-07 1359
123 [mysql] 서브쿼리(subquery) + 1 title: MoonBlonix 2017-12-07 1889
122 [jQuery] select box 제어 title: MoonBlonix 2017-10-14 1637
121 [mysql] mysqli_fetch_array, mysqli_fetch_assoc 비교 title: MoonBlonix 2017-10-12 1476
120 [php] 조회수 중복방지 구현 + 1 title: MoonBlonix 2017-10-06 1571
119 [mysql] JOIN 사용 + 2 title: MoonBlonix 2017-10-04 1373
118 [DataBase] ORM(Object-Relational Mappings)에 대하여 title: MoonBlonix 2017-10-04 1340
117 CK에디터 파일(백업용) file title: MoonBlonix 2017-09-25 1549
» [javascript] js, css 파일 동적 로딩 title: MoonBlonix 2017-09-20 1396
115 [web] 페이지 속도 개선 + 1 title: MoonBlonix 2017-09-17 1376
114 [jQuery] html 갈아엎기 title: MoonBlonix 2017-09-16 1616
113 [jQuery] 성능 최적화 title: MoonBlonix 2017-09-15 1857