You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在特定页面隐藏Smartsupp在线聊天的JavaScript代码

实现Smartsupp在线聊天脚本在特定页面不加载的方案

核心思路是通过判断当前页面的URL路径,仅在非目标页面加载Smartsupp脚本,具体修改如下:

修改后的代码

<!-- Smartsupp Live Chat 脚本 - 排除特定页面加载 -->
<script type="text/javascript">
// 定义需要排除的页面路径(可根据实际需求修改)
const excludedPath = '/X1XY';
// 获取当前页面的路径(域名之后的部分)
const currentPath = window.location.pathname;

// 仅当当前页面不是排除页面时,加载Smartsupp
if (!currentPath.includes(excludedPath)) {
  var _smartsupp = _smartsupp || {};
  _smartsupp.key = '123456789';
  window.smartsupp||(function(d) {
    var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
    s=d.getElementsByTagName('script')[0];c=d.createElement('script');
    c.type='text/javascript';c.charset='utf-8';c.async=true;
    c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
  })(document);
}
</script>

逻辑说明

  • 先定义要排除的页面路径excludedPath,如果需要排除多个页面,可以改成数组形式,比如:
    const excludedPaths = ['/X1XY', '/another-target-page'];
    // 对应判断条件改为:
    if (!excludedPaths.some(path => currentPath.includes(path))) {
      // 加载Smartsupp的代码
    }
    
  • window.location.pathname用于获取当前页面的路径部分(比如domain/X1XY对应的路径是/X1XY)
  • 用includes()方法判断当前路径是否包含排除路径,若不包含则执行脚本加载逻辑

更严格的精确匹配(可选)

如果需要完全匹配路径(比如仅当路径严格等于/X1XY时才排除,而非包含该字符串),可以将判断条件改为:

if (currentPath !== excludedPath) {
  // 加载Smartsupp的代码
}

内容的提问来源于stack exchange,提问作者Chad Davis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 09:02:52