질문과 답변

2026.03.02 17:42

위젯은 어떻게 만드나요?

수고하십니다.

기존의 위젯에 덮어 씌워 보면 노출이 되지 않는데
방법이 있을까요?

조언 좀 부탁드립니다.

감사합니다.

<div id="pc-ad-container"></div>

<script>
(function() {
// 가로 폭이 768px보다 크면 PC로 간주
if (window.innerWidth > 768) {
var container = document.getElementById('pc-ad-container');
// 스크립트 태그 생성
var script = document.createElement('script');
script.async = true;
script.setAttribute('data-cfasync', 'false');
script.src = 'https://.../invoke.js';
// 광고 컨테이너 생성
var adDiv = document.createElement('div');
adDiv.id = 'container-12345678';
// 페이지에 삽입
container.appendChild(script);
container.appendChild(adDiv);
}
})();
</script>
  • 공유링크 복사
    미니홈 쪽지 구독하기
    구독하고 알림받기

    댓글목록

    profile_image
    리빌더미니홈 1:1 대화하기  6시간 전

    안녕하세요.
    위젯에 <div id="pc-ad-container"></div> 이것만 넣어주시고,
    tail 쪽에서 아래와같이 넣어보세요!

    <script>
    (function () {
      function rbInitPcAdOnce() {
        if (window.innerWidth <= 768) return false;

        var container = document.getElementById('pc-ad-container');
        if (!container) return false;

        var slotId = 'container-12345678';
        var slot = document.getElementById(slotId);
        if (!slot) {
          slot = document.createElement('div');
          slot.id = slotId;
          container.appendChild(slot);
        }

        var src = 'https://.../invoke.js';

        var exists = document.querySelector('script[data-rb-ad="pc"][src="' + src + '"]');
        if (exists) return true;

        var s = document.createElement('script');
        s.async = true;
        s.setAttribute('data-cfasync', 'false');
        s.setAttribute('data-rb-ad', 'pc');
        s.src = src;

        (document.head || document.documentElement).appendChild(s);

        return true;
      }

      // 최초 한번 시도
      if (rbInitPcAdOnce()) return;

      // ajax로 dom이 나중에 들어오는 경우 감시
      if (!('MutationObserver' in window)) {
        // 폴백
        var tries = 0;
        var t = setInterval(function () {
          tries++;
          if (rbInitPcAdOnce() || tries > 40) clearInterval(t);
        }, 250);
        return;
      }

      var ob = new MutationObserver(function () {
        if (rbInitPcAdOnce()) ob.disconnect();
      });

      ob.observe(document.documentElement, { childList: true, subtree: true });
    })();
    </script>


    테스트를 못해봐서 안될 수 도 있습니다. 위젯은 ajax로 로드되는방식이라
    위젯안에 스크립트를 넣으면 실행이 되지 않을 수 있습니다.
    2.2.6 에서 개선될 수 있습니다.

    2026-03-02 22:05