本文将帮助您将 Widget 设置为仅显示在网站的特定页面上。对于有权访问网站代码并希望完全控制 Widget 显示位置的用户,此选项非常有用。

如何在特定页面上显示窗口小部件

这个过程背后的概念很简单。通过在代码中输入 URL,Tidio 将仅在配置的页面上可见。它将隐藏在与定义的链接不匹配的任何其他 URL 中。

让我们看 一个例子:

我们已将 URL: http://mystore.com/products/black/ 添加到代码中。在这种情况下,小组件将显示在包含此短语的所有地址中。

该 Widget 不会显示在:

  • http://mystore.com/about
  • http://mystore.com/contact
  • http://mystore.com/blog

但它会出现在:

  • http://mystore.com/products/black/
  • http://mystore.com/products/black/shoes
  • http://mystore.com/products/black/accessories

法典

要应用此选项,请执行以下步骤:

  1. 此代码需要在脚本之后加载,因此代码应放在 Tidio JavaScript 代码的下方,如果您使用的是 Tidio 插件,则应放置在 Tidio 代码的上方</body>
  2. 复制并粘贴下面的代码,或在我们的 Codepen 页面上找到代码。

如果您有任何其他问题,请通过 support@tidio.net 向我们的支持团队发送消息

<script async src="https://code.tidio.co/fouwfr0cnygz4sj8kttyv0cz1rpaayva.js"></script>
<script>
(function() {

// שנה כתובות URL מורשות כאן
var whitelistedUrls = [
'http://tidio.com',
];
// אל תשנה את הסקריפט לאחר שורה זו


var shouldShowWidget = (function isCurrentUrlWhitelisted() {
var currentUrl = window.location.href;
var isWhitelisted = false;
whitelistedUrls.forEach(url => {
if (currentUrl.indexOf(url) > -1) {
isWhitelisted = true;
}
})
return isWhitelisted;
})();

function onTidioChatApiReady() {
if (shouldShowWidget) {
window.tidioChatApi.show();
}
else {
window.tidioChatApi.hide();
}
}
if (window.tidioChatApi) {
window.tidioChatApi.on('ready', onTidioChatApiReady)
}
else {
document.addEventListener('tidioChat-ready', onTidioChatApiReady);
}
})();
</script>