例如:baidu.com和www.baidu.com,地址栏里输入的不同获取的域名host是不一样的,虽然后者带了www. 但baidu.com都是包含的
这种方法适用于域名比较多的情况,用来显示网站底部备案号的方法
var urlhost = window.location.host;
var icpno = "";
if (isStrNull(urlhost) != "") {
var host = urlhost.replace("www.", "")
switch (host) {
case "baidu.com":
icpno = "京ICP证030173号-1";
break;
case "sogou.com":
icpno = "京ICP备11001839号-2";
break;
}
}
$(".beianhost").text(icpno);
function isStrNull(str) {
if (str == "null" || str == "undefined" || str == undefined || typeof (str) == "undefined" || str == null) {
str = "";
}
return str.toString();
}