로컬에서 html에서 html 파일 인클루드 채택완료
그누보드초보이용자
6년 전
조회 6,400
로컬에서 html에서 html 파일 인클루드
방법이있을까요?
$("#header").load("header.html")
이방법으로 하려는데;
blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
이 에러메시지가 나와서요.
댓글을 작성하려면 로그인이 필요합니다.
답변 3개
채택된 답변
+20 포인트
6년 전
이렇게 해보심이..
</p>
<p><script>
//includeHTML() 함수
function includeHTML() {
var z, i, elmnt, file, xhttp;
/*loop through a collection of all HTML elements:*/
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain atrribute:*/
file = elmnt.getAttribute("html-include");
if (file) {
/*make an HTTP request using the attribute value as the file name:*/
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) { elmnt.innerHTML = this.responseText; }
if (this.status == 404) { elmnt.innerHTML = "Page not found."; }
/*remove the attribute, and call this function once more:*/
elmnt.removeAttribute("html-include");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
/*exit the function:*/
return;
}
}
};</p>
<p> $(document).ready(function() {
//includeHTML() 함수 실행
includeHTML();
});
</script></p>
<p><!-- 인클루드해서 넣을 HTML 주소를 html-include=""에 넣음 -->
<div id="header" html-include="header.html"></div></p>
<p>
로그인 후 평가할 수 있습니다
답변에 대한 댓글 2개
�
그누보드초보이용자
6년 전
똑같은에러이네요..
j
jun31019
6년 전
아 동일한 이유겠네요;; 서버에서 실행해야 되는거겠네요;;
혹시 에디터플러스를 사용하시면 일단 테스트는 가능할 거 같은데요.
편집창에서 Ctrl + B 누르시면 에디터플러스 창내에서 브라우저가 열려서 화면은 볼 수 있을거 같아요.
혹시 에디터플러스를 사용하시면 일단 테스트는 가능할 거 같은데요.
편집창에서 Ctrl + B 누르시면 에디터플러스 창내에서 브라우저가 열려서 화면은 볼 수 있을거 같아요.
댓글을 작성하려면 로그인이 필요합니다.
6년 전
내컴퓨터에 Autoset 등 APM설치 프로그램으로 서버 구축후
ajax관련 함수 - 여기서는 load() - 를 사용하는 경우 그런 문제가 생기더군요.
실제 서버에 올려 테스트해 보시죠.
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
�
그누보드초보이용자
6년 전
네 실서버면 가능할거같네요
ㅜㅜ
ㅜㅜ
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인