HEX
Server: Apache/2.4.37 (CentOS Stream) OpenSSL/1.1.1k
System: Linux ysnet.com.tw 4.18.0-553.5.1.el8.x86_64 #1 SMP Tue May 21 05:46:01 UTC 2024 x86_64
User: test (521)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //proc/thread-self/cwd/js/iframe-resizer-helper.js
(function () {
  let lastHeight = 0;
  let animationFrameId = null;

  function sendHeightToParent(height) {
    window.parent.postMessage({
      type: 'ysnet-iframe-resize',
      height: height
    }, window.location.origin);
  }

  function trackHeightContinuously() {
    const newHeight = document.body.scrollHeight;

    if (newHeight !== lastHeight) {
      lastHeight = newHeight;
      sendHeightToParent(newHeight);
    }

    animationFrameId = requestAnimationFrame(trackHeightContinuously);
  }

  function startTracking() {
    cancelAnimationFrame(animationFrameId);
    animationFrameId = requestAnimationFrame(trackHeightContinuously);
  }

  // 確保 document.body 存在才執行
  if (document.readyState === "complete" || document.readyState === "interactive") {
    startTracking();
  } else {
    window.addEventListener("DOMContentLoaded", startTracking);
  }

  // 若有頁面跳轉到同一個 iframe 中的其他頁面,也重新啟動追蹤
  window.addEventListener("load", () => {
    setTimeout(startTracking, 200); // 預留一下 DOM 建立完成
  });

  // 提供外部手動呼叫
  window.notifyParentOfHeightChange = () => {
    sendHeightToParent(document.body.scrollHeight);
  };
})();