반응형
#js에서 import 하기 (파일명예:test_js.js)
//제이쿼리 import
var str = "https://code.jquery.com/jquery-latest.min.js";
function loadScript(url, callback) {
var script = document.createElement('script');
script.src = url;
script.onload = callback;
document.getElementsByTagName('head')[0].appendChild(script);
}
var myloaded = function() {
document.write(str); // hello 출력됨
}
loadScript(str);
//css import
var cssId = 'box_wrap'; // you could encode the css path itself to generate id..
if (!document.getElementById(cssId))
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '홈페이지주소/css/test_css.css';
link.media = 'all';
head.appendChild(link);
}
window.onload = function(){
var temp_html ='html 마크업 코드';
$(function(){
$('body').append(temp_html);
});
}
#위의 코드를 다른 사이트에서 불러오기
<script src='위의사이트가 있는 사이트명/test_js.js'></script>
*파일위치를 적어주면 그대로 불러올 수 있음
728x90
반응형
'JS & jQuery' 카테고리의 다른 글
비메오 및 YTPlayer (0) | 2022.08.16 |
---|---|
scroll img rotate (0) | 2022.07.11 |
별점 (0) | 2022.03.07 |
파일 이미지 미리보기 (0) | 2022.03.07 |
자바스크립트 ip 확인 (0) | 2022.03.07 |