0

如何在 5 秒后初始化 Freshdesk 在线聊天小部件?

settimeout(function(e) {
    function initFreshChat() {

        window.fcWidget.init({
            token: "token number",
            host: "https://wchat.freshchat.com"
       });
    }

    function initialize(i,t){var e;i.getElementById(t)?initFreshChat():((e=i.createElement("script")).id=t,e.async=!0,e.src="https://wchat.freshchat.com/js/widget.js",e.onload=initFreshChat,i.head.appendChild(e))}function initiateCall(){initialize(document,"freshchat-js-sdk")}window.addEventListener?window.addEventListener("load",initiateCall,!1):window.attachEvent("load",initiateCall,!1);
}, 5000);

不工作...

4

1 回答 1

2

您可以使用此代码段。确保输入token

<script>
  function initFreshChat() {
    window.fcWidget.init({
      token: "<FC_TOKEN>",
      host: "https://wchat.freshchat.com"
    });
  }
  function initialize(i, t) { var e; i.getElementById(t) ? initFreshChat() : ((e = i.createElement("script")).id = t, e.async = !0, e.src = "https://wchat.freshchat.com/js/widget.js", e.onload = initFreshChat, i.head.appendChild(e)) } function initiateCall() { setTimeout(() => { initialize(document, "freshchat-js-sdk") }, 5000) } window.addEventListener ? window.addEventListener("load", initiateCall, !1) : window.attachEvent("load", initiateCall, !1);
</script>

setTimeout 放置在initiateCall()函数 内部在此处输入图像描述

为什么将所有内容都包含在 setTimeout 中不起作用?

将初始化片段包装在 setTimeout 中不起作用,因为它会延迟加载事件的注册(因此不会触发加载事件侦听器)。加载事件侦听器的回调是initiateCall(). 将 setTimeout()放入 initiateCall()其中以实现预期结果是有意义的

在此处输入图像描述

于 2019-10-16T14:31:48.237 回答