chat-embed.ts 548 B

1234567891011121314151617
  1. /**
  2. * 访客 /chat 是否处于「被宿主 iframe 嵌入」模式。
  3. * 嵌入时不展示页内 FloatingButton,直接铺满 iframe 显示 ChatWidget。
  4. */
  5. export function isChatEmbedMode(): boolean {
  6. if (typeof window === "undefined") return false;
  7. const q = new URLSearchParams(window.location.search);
  8. if (q.get("embed") === "1" || q.get("embed") === "true") return true;
  9. try {
  10. return window.self !== window.top;
  11. } catch {
  12. // 跨域 iframe 访问 top 会抛错,说明正在被外部站点嵌入
  13. return true;
  14. }
  15. }