一个空间绑定两个域名,判断不同域名使用不同的百度统计

<script>
switch(window.location.hostname){
var surl = window.location.host.split(‘.’);
var u = ”;
for (var i in surl) {
var point = i < (surl.length – 1) ? ‘.’ : ”;
if (i > 0) {
u += surl[i] + point;
}
}
function bd_hm(k) {
var _hmt = _hmt || [];
(function () {
var hm = document.createElement(“script”);
hm.src = “https://hm.baidu.com/hm.js?” + k + “”;
var s = document.getElementsByTagName(“script”)[0];
s.parentNode.insertBefore(hm, s);
})();
}

switch (u) {
case ‘aaa.com’:
bd_hm(‘e104554a1e007d810e2f05xxxx’);
break;

case ‘bbb.com’:
bd_hm(‘e104554a1e007d810e2f053yyyyy’);
break;

case ‘ccc.com’:
bd_hm(‘de15451aaaf06969b4cb077zzzzz’);
break;

default:
}

</script>

Posted in

发表评论

邮箱地址不会被公开。 必填项已用*标注