有多个域名指向同一个主机空间,要实现用 www.abc.com 域名访问该网站的话,调用A.js,用www.def.com 域名访问该网站的话,调用B.js,其他域名访问则调用C.js。
var str1=window.document.location.hostname;
if (str1=="http://www.abc.com")
{
document.writeln('
document.writeln('' + 'ipt>');
}
else if (str1=="http://www.def.com")
{
document.writeln('
document.writeln('' + 'ipt>');
}
else
{
document.writeln('
document.writeln('' + 'ipt>');
}
---------------------------------
JS代码代码如下:
name=window.location.host; //获取玉米
name=name.toLowerCase() //将大写字母转换小写
if (name.indexOf("baidu.com")>0)
document.write('广告代码1')
else if (name.indexOf("google.com")>0)
document.write('广告代码2')
else
document.write('广告代码3')