테스트 사이트 - 개발 중인 베타 버전입니다

body 테그에 펑션을 넣은뒤 채택완료

8년 전 조회 1,758

head.sub에 

테그가 있자나요..

특정게시판 수정페이지에서 쓰기 위해

을 넣었는데...

문제는 head.php는 head.sub.php를 불러오는 그누 구조때문에

모든 게시판에서 요소검사해보니 onscroll="myFunction()" 이 없다고 애러를 쏟아내는데

이런 경우는 어떻게 처리해야 하는지요?

*필요상 적용한 수정페이지에서는 당연히 해당 id가 있으니 애러 없구요,,

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

채택된 답변
+20 포인트

head.php나 

head.sub.php 에다가 

즉, 공통영역에

</p><p><script></p><pre style="white-space: pre-wrap; word-wrap: break-word; font-size: 15px; background-color: rgb(238, 238, 238); color: rgb(51, 51, 51); box-sizing: content-box !important; margin-top: 0px !important; margin-bottom: 0px !important; line-height: 1.1em !important; font-family: source-code-pro, Consolas, monospace !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: auto !important;"><div class="container" style="box-sizing: content-box !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: auto !important;"><div class="line" style="box-sizing: content-box !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: auto !important; white-space: pre !important;"><code style="word-wrap: normal; display: block; box-sizing: content-box !important; font-size: 1em !important; line-height: 1.1em !important; padding: 0px !important; background: none !important; border-radius: 0px !important; font-family: source-code-pro, Consolas, monospace !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: auto !important;">$( <span class="string" style="box-sizing: border-box; color: rgb(221, 17, 68);">"body"</span> ).scroll(<span class="keyword" style="box-sizing: border-box; font-weight: bold;">function</span>() {</code></div></div><div class="container" style="box-sizing: content-box !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: auto !important;"><div class="line" style="box-sizing: content-box !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: auto !important; white-space: pre !important;"><code style="word-wrap: normal; display: block; box-sizing: content-box !important; font-size: 1em !important; line-height: 1.1em !important; padding: 0px !important; background: none !important; border-radius: 0px !important; font-family: source-code-pro, Consolas, monospace !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: auto !important;"><span style="color: rgb(0, 0, 0); font-family: 돋움; font-size: 14.6667px; white-space: normal;">    if (</span><span style="white-space: normal; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.6667px;">myFunction)  </span><span style="white-space: normal; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.6667px;">myFunction();</span>
</code></div></div><div class="container" style="box-sizing: content-box !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: auto !important;"><div class="line" style="box-sizing: content-box !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; min-height: auto !important; white-space: pre !important;"><code style="word-wrap: normal; display: block; box-sizing: content-box !important; font-size: 1em !important; line-height: 1.1em !important; padding: 0px !important; background: none !important; border-radius: 0px !important; font-family: source-code-pro, Consolas, monospace !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; min-height: auto !important;">});</code></div></div></pre><p style="margin-left: 0px;"><span style="font-size: 11pt;"></script></span> </p><p style="margin-left: 0px;"><span style="font-size: 11pt;">

을 넣으시면 해결되지 않을까요?

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

감사합니다~ 참고하여 해결하였습니다.
head.sub.php
<body 여기에 넣어야 하고 > 그러면 모든 페이지에서 적용되므로
스크립트가
<script>
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;

function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
</script>
이거라 head.sub.php에 이걸 넣고
정작 쓰고자 하는데는

getElementById("navbar2"); 이런식으로 처리햇습니다.
그러니 id가 충돌하지 않고,,잘됩니다.
바디테그에 뭔가 넣어야 할때 이런식으로 꼼수로 처리하면 될거 같습니다.ㅋ

댓글을 작성하려면 로그인이 필요합니다.

그러면 모든 페이지에서 적용되므로 ... 

이 기능보다 좀더 포괄적인

jquery 가

$(document).ready(function() {

});

이거거든요

동일하게 작동시키는 약식이

$(function() {

   //여기에 넣어주면

   // body onload = "functions....();" 와 동일합니다.

   // 장점은 여러개를 넣기에 가독성이 좋다는거죠

});

https://api.jquery.com/ready/">https://api.jquery.com/ready/ 

참고하세요

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인

전체 질문 목록