AJAX/jQuery-JSON이로드 된 내 페이지에 광고를 표시하고 싶습니다. javascript를 사용하여 document.write로 스크립트를로드하는 방법
- 스크립트 :
- 파일 xxxxx.js이 document.write를 들어 있습니다();
이 스크립트를 통합하여 document.write를 해석하는 방법. 그리고 왜 작동하지 않습니까?
내 테스트는 경고 ('hello 1')가 표시되었지만 경고 ('hello 2')가 포함 된 document.write가 아니기 때문에 스크립트가 실행되었음을 나타냅니다.
를 호출 DOM에 직접 파일 "안녕하세요 1"과 "안녕하세요이"잘 실행
test.js
alert("hello 1");
document.write('<scr'+'ipt type="text/javascript">alert("hello 2");</scr'+'ipt>');
지수 :
<body>
<script>
function loadScriptJs() {
var s = document.createElement('script');
s.src = 'test.js';
s.type = 'text/javascript';
document.getElementById("pub").appendChild(s);
}
</script>
<div id="pub">
PUB A AJOUTER CI DESSOUS EN JAVASCRIPT :
<!-- appel direct de la pub
<script src="test.js" type="text/javascript"></script> -->
</div>
<script> loadScriptJs(); </script>
</body>
당신이 bfavaretto 감사하지만 각 부하에 대한 타격을하기 위해 간단한 솔루션 을 사용할 수 없습니다 : 나는 스크립트를로드하는 각 내용을로드 할 함수는로드 한 후 실행됩니다 내 콘텐츠 – beberahim
좋아요, 그렇다면'test.js'에서 document.write를 사용할 수 없습니다. 내 업데이트를 참조하십시오. – bfavaretto