zoukankan      html  css  js  c++  java
  • h5集成环信在线客服自定义窗口

    自定义客服窗口从底部弹出

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    </head>
    <body>
    
    <a href="javascript:OpenChat();">咨询客服</a>
    <!-- 自定义一个容器,嵌入iframe放客服窗口 -->
    <div id="frameChat" style="display:none; position:fixed; z-index:2000; bottom:0px; left:0px; right:0px; height:580px;background:#fff;">
    <iframe id="chatFrame" src="kefu.html" style="height:100%;100%" frameborder="0"></iframe>
    </div>
    
    <script>
    let openchat = false;
    function OpenChat(){
        openchat = true;
        document.getElementById('frameChat').style.display = '';
        setTimeout(function(){
            document.getElementById('chatFrame').contentWindow.document.getElementById('kefu').click();
        },100);
    }
    function hideChat(){
        openchat = false;
        document.getElementById('frameChat').style.display = 'none';
    }
    //接收iframe发回的消息
    window.addEventListener('message', function (e) {
        let data = e.data;
        if(data.c == 'hide'){
            hideChat();
        }
        if(data.c == 'msg' && !openchat){
            let t = data.t.message.value;
            console.log(t);
        }
    }, false);
    </script>
    </body>
    </html>

    kefu.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    </head>
    <body>
    <a href='javascript:;' onclick='easemobim.bind({configId: "426fae41-c211-4a9c-b74e-088a1edf39e3"})' id="kefu" style="position:absolute; left:-1000px;">#</a>
    <script>
    window.easemobim = window.easemobim || {};
    easemobim.config = {
        hide: true,
        autoConnect: true,
        hideKeyboard: true,
        visitor: {
            trueName: '',
            qq: '',
            phone: '',
            companyName: '',
            userNickname: '',
            description: '来源'+document.referrer,
            email: ''
        },
        onmessage: function ( message ) { 
            window.parent.postMessage({c:'msg', t:message}, '*');
        }
    };
    </script>
    <script src='//kefu.easemob.com/webim/easemob.js'></script>
    
    <script>
    const body = document.body;
    // 监听body的class属性变化 判断是否客服隐藏窗口
    const observer = new MutationObserver(mutationsList => {
        if(body.getAttribute('class') != null && body.getAttribute('class').replace(/s+/g,"") == ''){
            window.parent.postMessage({c:'hide'}, '*');
        }
    });
    
    observer.observe(body, {
        attributes: true,
        childList: true,
        subtree: true,
    });
    </script>
    </body>
    </html>
  • 相关阅读:
    SQL Server中出现用户或角色在当前数据库已经存在的问题的解决
    vs项目中添加lib库的方法总结
    【转载】C++ Socket通信总结(附C++实现)
    【转载】windows socket函数详解
    如何在 Debian 9 下安装 LEMP 和 WHMCS 7.5
    13个云计算基础设施自动化的最佳工具
    5分钟打造一个前端性能监控工具
    我的处女作——设计模式之状态模式
    IOS逆向分析笔记——replay逆向分析
    IOS逆向分析——GL脚本的提取
  • 原文地址:https://www.cnblogs.com/6min/p/11661125.html
Copyright © 2011-2022 走看看