【发布时间】:2015-08-27 09:30:19
【问题描述】:
尝试使变量__lc.group 动态化,以便根据页面的 URL 设置组号,这是我尝试过的代码,但似乎没有用。
不知道为什么它不起作用。这是为现场实时聊天功能动态设置组变量,以便我可以为站点的不同页面设置不同的运算符。
if(window.location.href.indexOf("netball") > -1) {
__lc.group = 1;
}
if(window.location.href.indexOf("football") > -1) {
__lc.group = 5;
}
if(window.location.href.indexOf("basketball") > -1) {
__lc.group = 2;
}
if(window.location.href.indexOf("social") > -1) {
__lc.group = 3;
}
if(window.location.href.indexOf("fitness") > -1) {
__lc.group = 6;
}
if(window.location.href.indexOf("softball") > -1) {
__lc.group = 4;
}
if(window.location.href.indexOf("volleyball") > -1) {
__lc.group = 4;
}
if(window.location.href.indexOf("dodgeball") > -1) {
__lc.group = 4;
}
if(window.location.href.indexOf("american") > -1) {
__lc.group = 4;
}
if(window.location.href.indexOf("ultimate") > -1) {
__lc.group = 4;
}
完整的脚本代码为:
<!-- Start of LiveChat (www.livechatinc.com) code -->
<script type="text/javascript">
var __lc = {};
__lc.license = XXXXX;
if(window.location.href.indexOf("netball") > -1) {
__lc.group = 1;
}
if(window.location.href.indexOf("football") > -1) {
__lc.group = 5;
}
if(window.location.href.indexOf("basketball") > -1) {
__lc.group = 2;
}
if(window.location.href.indexOf("social") > -1) {
__lc.group = 3;
}
if(window.location.href.indexOf("fitness") > -1) {
__lc.group = 6;
}
if(window.location.href.indexOf("softball") > -1) {
__lc.group = 4;
}
if(window.location.href.indexOf("volleyball") > -1) {
__lc.group = 4;
}
if(window.location.href.indexOf("dodgeball") > -1) {
__lc.group = 4;
}
if(window.location.href.indexOf("american") > -1) {
__lc.group = 4;
}
if(window.location.href.indexOf("ultimate") > -1) {
__lc.group = 4;
}
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})();
</script>
<!-- End of LiveChat code -->
【问题讨论】:
-
“但它似乎没有用”到底是什么意思?你有任何错误吗?
__lc变量在使用前你定义了吗? -
对不起,我已经添加了完整的代码。目前它没有改变组变量:livechatinc.com/kb/livechat-for-multiple-websites
标签: javascript variables if-statement livechat