gpt4 book ai didi

javascript - Freshdesk - 超时后初始化

转载 作者:行者123 更新时间:2023-12-02 22:48:25 25 4
gpt4 key购买 nike

如何在 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);

不工作...

最佳答案

您可以使用此代码片段。确保输入 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() 函数内 enter image description here

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

将初始化片段包装在 setTimeout 内将不起作用,因为它会推迟加载事件的注册(从而不会触发加载事件监听器)。加载事件监听器的回调是initiateCall()。将 setTimeout() 放置在内部initiateCall()以实现预期结果是有意义的

enter image description here

关于javascript - Freshdesk - 超时后初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58285879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com