Shopify如何在页面上添加一个链接调用shopify inbox

释放双眼,带上耳机,听听看~!

我们有时候在联系我们或者blog页面,需要添加一个链接,点击后启用shopify inbox聊天窗口,那么我们如何实现这个小功能呢。方法如下。

方法1 推荐

<a href="#!" id="custom-live-chat">Live chat with us</a>

<script>
  document.getElementById('custom-live-chat').onclick = function(e) {
    e.preventDefault(); 
    if(document.getElementById("dummy-chat-button-iframe")){ 
      document.getElementById("dummy-chat-button-iframe").contentWindow.document.getElementById("dummy-chat-button").addEventListener("click", dummyChatButtonIframe(), true);
    }else{
      document.getElementById("ShopifyChat").contentWindow.document.getElementsByClassName("chat-toggle")[0].addEventListener("click", ShopifyChat(), true);
    }
  }

  function dummyChatButtonIframe() {
       var iframe = document.getElementById("dummy-chat-button-iframe");
       var elmnt  = iframe.contentWindow.document.getElementById("dummy-chat-button");
       elmnt.click(); 
  }

  function ShopifyChat() { 
    var iframe = document.getElementById("ShopifyChat");
    var elmnt = iframe.contentWindow.document.getElementsByClassName("chat-toggle")[0];
    elmnt.click();
}
</script>

方法2

<a href="#!" onclick="document.getElementById('dummy-chat-button-iframe').contentDocument.querySelector('.chat-toggle').click()">Live Char</a>
<script type="text/javascript">
     const needhelp = document.getElementById('needhelp-button');
     needhelp.addEventListener('click', () => {
     document.getElementById('ShopifyChat').contentDocument.querySelector('.chat-toggle').click()       
    });
</script>

方法3(此效果不好,会刷新整个页面)

使用超链接:
https://<Your website>/?show_chat

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
Shopify主题开发独立站教程

shopify liquid语言之for循环小技巧(判断是否是第一个元素)

2023-6-20 19:54:50

Shopify插件推荐独立站教程

Shopify swatch变体插件自定义显示变体图片-( GLO Color Swatch,Variant Image)

2023-6-29 17:58:04

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索