网站开发兼职_医院网站建设_医院网站开发_医疗网站建设

当前位置: > 建站教程 > 运营推广 >

商务通换快商通弹窗代码对话框点击没反应不管用了怎么办

发布时间:2018-08-06 作者:医院网站制作 浏览: 关键词: 对话框 商务通 快商通 弹窗代码

企业里用的商务通软件也快商通比起来简直就是小巫见大巫了,越来越多的企业放弃商务通,开始使用快商通了。

在使用商务通的时候,我们的程序员通常会开发好多定制代码,让对话框和网页显示的足够整洁和比较人性化。

 

在拿到快商通软件的时候,我们从快商通的后台里面只能看到如下两张图片说明。

 

 

如果我们只把个给定的代码放到原网站里,之前的弹窗链接统统都不能点开,原来做的那么好看的效果都作废了吗?

别急,我这给您提供了非常简单的快商通兼容商务通的函数,引入代码之后添加一个函数,原来的程序代码又会变得能用了。

首先我们先按官方要求的那样引用快商通代码,这一步必不可少,不可偷懒。

<script>

var onKST = function (text) {

//请替换成"生成代码 - 链接地址" 中的链接地址,不要去其他地方复制

ksChatLink = 'https://viph19-hztk11.kuaishang.cn/bs/im.htm?cSource=1&cas=你cas&fi=你的fi';

/**

* 若强行打开新窗口,则放开设置,不设置则手机不打开新窗口,pc打开新窗口,此设置只对当前自定义事件有效

* 若想全局生效,包括快商通默认的打开聊天窗口事件,则将此变量ksUserDefinedOpenNewChatWin定义在ks.js前即可

*/

//var ksUserDefinedOpenNewChatWin=true;

//验证参数是否存在

function checkQueryString(params, name) {

if (!params)return false;

return new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i").test(params);

}

//获取URL参数值

function getQueryString(url, name) {

var index = url.indexOf('?');

if (index == -1)return '';

url = url.substr(index + 1, url.length);

var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");

var r = url.match(reg);

if (r != null) return unescape(r[2]);

return '';

}

var openNewChatWin;

var localArr = ksChatLink.split("?");

localArr.push("");

if (typeof ksUserDefinedOpenNewChatWin != 'undefined' && ksUserDefinedOpenNewChatWin == true) {

openNewChatWin = true;

} else if (checkQueryString(localArr[1], 'ism')) {

openNewChatWin = false;

} else {

openNewChatWin = true;

}

//打开快商通聊天窗口链接

function ksOpenLink() {

var appendTailUrl = '';

try {

var cas = getQueryString(ksChatLink, 'cas');

if (cas) {

var vi = '';

var dc = document.cookie.match(new RegExp('(^| )' + cas + '_KS_' + cas + '=([^;]*)(;|$)'));

if (dc != null) {

vi = unescape(dc[2]);

}

if (vi) {

appendTailUrl += '&vi=' + vi;

}

}

} catch (e) {

}

var ref = "";

try {

if (opener.document.referrer.length > 0) {

ref = opener.document.referrer;

}

} catch (e) {

ref = document.referrer;

}

if (!ref || ref.length == 0) {

ref = document.referrer;

}

//对话网址

appendTailUrl += '&dp=' + encodeURIComponent(window.location.href);

//访客来源

if (ref)appendTailUrl += '&ref=' + encodeURIComponent(ref);

//对话标识

if (text)appendTailUrl += '&sText=' + encodeURIComponent(text);

if (ksChatLink.indexOf('?') == -1) {

appendTailUrl = appendTailUrl.substring(1) + '?';

}

ksChatLink += appendTailUrl;

//根据openNewChatWin设置打开聊天窗口

if (!openNewChatWin) {

window.location.href = ksChatLink;

} else {

var ksWin = window.open(ksChatLink, '_blank');

if (ksWin) {

try {

ksWin.focus();

} catch (e) {

} //将焦点定位到聊天窗口

}

}

}

//如果快商通代码有加载完成,则使用快商通默认的打开聊天窗口事件,否则使用自定义的打开事件

if (typeof KS != 'undefined') {

var p = {};

if (text)p['sText'] = text;

if (openNewChatWin)p['oTarget'] = '_blank';

try {

if (typeof KS.openChatWin == 'function') {

KS.openChatWin(p);

} else if (typeof KS.openChatLink == 'function') {

KS.openChatLink(p);

} else {

ksOpenLink();

}

} catch (e) {

ksOpenLink();

}

} else {

ksOpenLink();

}

};

以上快商通的处理函数添加完之后,我们添加一个兼容商务通的函数,这样,即使您的几百个专题里都是写的商务通的固定链接,我们这样改动之后,仍然可以弹出对话框。

function openZoosUrl() {

return onKST();

}

好了,管不管用,你试试看就知道了,欢迎收藏,欢迎关注我的头条号:前端技术分享,欢迎浏览我的作品,有事儿您说话!
如果想把代码放在公用的外部js里调用,需要这样写

document.writeln("<script type=\'text/javascript\' src=\'https://viph19-hztk11.kuaishang.cn/bs/ks.j?cI=您的ci版权所有医院网站开发mediab.cn&fI=您的fi&ism=1\' charset=\'utf-8\'></script>");//ism参数表示手机端代码pc端删除掉这个参数


document.writeln("<script language=javascript>");

document.writeln("var onKST = function (text) {");
document.writeln("");
document.writeln("    //请替换成\'生成代码 - 链接地址\' 中的链接地址,不要去其他地方复制");
document.writeln("");
document.writeln("    ksChatLink = \'https://viph19-hztk11.kuaishang.cn/bs/im.htm?cSource=1&cas=您的cas版权所有医院网站开发mediab.cn&fi=您的fi\';");
document.writeln("");
document.writeln("    /**");
document.writeln("");
document.writeln("     * 若强行打开新窗口,则放开设置,不设置则手机不打开新窗口,pc打开新窗口,此设置只对当前自定义事件有效");
document.writeln("");
document.writeln("     * 若想全局生效,包括快商通默认的打开聊天窗口事件,则将此变量ksUserDefinedOpenNewChatWin定义在ks.js前即可");
document.writeln("");
document.writeln("     */");
document.writeln("");
document.writeln("    //var ksUserDefinedOpenNewChatWin=true;");
document.writeln("");
document.writeln("");
document.writeln("    //验证参数是否存在");
document.writeln("");
document.writeln("    function checkQueryString(params, name) {");
document.writeln("");
document.writeln("        if (!params)return false;");
document.writeln("");
document.writeln("        return new RegExp(\'(^|&)\' + name + \'=([^&]*)(&|$)\', \'i\').test(params);");
document.writeln("");
document.writeln("    }");
document.writeln("");
document.writeln("    //获取URL参数值");
document.writeln("");
document.writeln("    function getQueryString(url, name) {");
document.writeln("");
document.writeln("        var index = url.indexOf(\'?\');");
document.writeln("");
document.writeln("        if (index == -1)return \'\';");
document.writeln("");
document.writeln("        url = url.substr(index + 1, url.length);");
document.writeln("");
document.writeln("        var reg = new RegExp(\'(^|&)\' + name + \'=([^&]*)(&|$)\', \'i\');");
document.writeln("");
document.writeln("        var r = url.match(reg);");
document.writeln("");
document.writeln("        if (r != null) return unescape(r[2]);");
document.writeln("");
document.writeln("        return \'\';");
document.writeln("");
document.writeln("    }");
document.writeln("");
document.writeln("    var openNewChatWin;");
document.writeln("");
document.writeln("    var localArr = ksChatLink.split(\'?\');");
document.writeln("");
document.writeln("    localArr.push(\'\');");
document.writeln("");
document.writeln("    if (typeof ksUserDefinedOpenNewChatWin != \'undefined\' && ksUserDefinedOpenNewChatWin == true) {");
document.writeln("");
document.writeln("        openNewChatWin = true;");
document.writeln("");
document.writeln("    } else if (checkQueryString(localArr[1], \'ism\')) {");
document.writeln("");
document.writeln("        openNewChatWin = false;");
document.writeln("");
document.writeln("    } else {");
document.writeln("");
document.writeln("        openNewChatWin = true;");
document.writeln("");
document.writeln("    }");
document.writeln("");
document.writeln("    //打开快商通聊天窗口链接");
document.writeln("");
document.writeln("    function ksOpenLink() {");
document.writeln("");
document.writeln("        var appendTailUrl = \'\';");
document.writeln("");
document.writeln("        try {");
document.writeln("");
document.writeln("            var cas = getQueryString(ksChatLink, \'cas\');");
document.writeln("");
document.writeln("            if (cas) {");
document.writeln("");
document.writeln("                var vi = \'\';");
document.writeln("");
document.writeln("                var dc = document.cookie.match(new RegExp(\'(^| )\' + cas + \'_KS_\' + cas + \'=([^;]*)(;|$)\'));");
document.writeln("");
document.writeln("                if (dc != null) {");
document.writeln("");
document.writeln("                    vi = unescape(dc[2]);");
document.writeln("");
document.writeln("                }");
document.writeln("");
document.writeln("                if (vi) {");
document.writeln("");
document.writeln("                    appendTailUrl += \'&vi=\' + vi;");
document.writeln("");
document.writeln("                }");
document.writeln("");
document.writeln("            }");
document.writeln("");
document.writeln("        } catch (e) {");
document.writeln("        }");
document.writeln("");
document.writeln("        var ref = \'\';");
document.writeln("");
document.writeln("        try {");
document.writeln("            if (opener.document.referrer.length > 0) {");
document.writeln("                ref = opener.document.referrer;");
document.writeln("            }");
document.writeln("        } catch (e) {");
document.writeln("            ref = document.referrer;");
document.writeln("        }");
document.writeln("");
document.writeln("        if (!ref || ref.length == 0) {");
document.writeln("            ref = document.referrer;");
document.writeln("        }");
document.writeln("");
document.writeln("        //对话网址");
document.writeln("");
document.writeln("        appendTailUrl += \'&dp=\' + encodeURIComponent(window.location.href);");
document.writeln("");
document.writeln("        //访客来源");
document.writeln("");
document.writeln("        if (ref)appendTailUrl += \'&ref=\' + encodeURIComponent(ref);");
document.writeln("");
document.writeln("        //对话标识");
document.writeln("");
document.writeln("        if (text)appendTailUrl += \'&sText=\' + encodeURIComponent(text);");
document.writeln("");
document.writeln("        if (ksChatLink.indexOf(\'?\') == -1) {");
document.writeln("            appendTailUrl = appendTailUrl.substring(1) + \'?\';");
document.writeln("        }");
document.writeln("");
document.writeln("        ksChatLink += appendTailUrl;");
document.writeln("");
document.writeln("        //根据openNewChatWin设置打开聊天窗口");
document.writeln("");
document.writeln("        if (!openNewChatWin) {");
document.writeln("");
document.writeln("            window.location.href = ksChatLink;");
document.writeln("");
document.writeln("        } else {");
document.writeln("");
document.writeln("            var ksWin = window.open(ksChatLink, \'_blank\');");
document.writeln("");
document.writeln("            if (ksWin) {");
document.writeln("");
document.writeln("                try {");
document.writeln("                    ksWin.focus();");
document.writeln("                } catch (e) {");
document.writeln("                } //将焦点定位到聊天窗口");
document.writeln("");
document.writeln("            }");
document.writeln("");
document.writeln("        }");
document.writeln("");
document.writeln("    }");
document.writeln("");
document.writeln("    //如果快商通代码有加载完成,则使用快商通默认的打开聊天窗口事件,否则使用自定义的打开事件");
document.writeln("");
document.writeln("    if (typeof KS != \'undefined\') {");
document.writeln("");
document.writeln("        var p = {};");
document.writeln("");
document.writeln("        if (text)p[\'sText\'] = text;");
document.writeln("");
document.writeln("        if (openNewChatWin)p[\'oTarget\'] = \'_blank\';");
document.writeln("");
document.writeln("        try {");
document.writeln("");
document.writeln("            if (typeof KS.openChatWin == \'function\') {");
document.writeln("");
document.writeln("                KS.openChatWin(p);");
document.writeln("");
document.writeln("            } else if (typeof KS.openChatLink == \'function\') {");
document.writeln("");
document.writeln("                KS.openChatLink(p);");
document.writeln("");
document.writeln("            } else {");
document.writeln("");
document.writeln("                ksOpenLink();");
document.writeln("");
document.writeln("            }");
document.writeln("");
document.writeln("        } catch (e) {");
document.writeln("");
document.writeln("            ksOpenLink();");
document.writeln("");
document.writeln("        }");
document.writeln("");
document.writeln("    } else {");
document.writeln("");
document.writeln("        ksOpenLink();");
document.writeln("");
document.writeln("    }");
document.writeln("");
document.writeln("};");
document.writeln("");
document.writeln("");
document.writeln("function openZoosUrl() {");
document.writeln("");
document.writeln("    return onKST();");
document.writeln("");
document.writeln("}");

document.writeln("</script>");

 

责任编辑:医院网站制作
共有人阅读,期待你的评论!评论
运营推广
二次开发
使用技巧
调试安装
运营推广