用JS获取当前域名并判断

JavaScript026

用JS获取当前域名并判断,第1张

//获取域名

host = window.location.host

host2=document.domain

if(host!="xxx.com") alert("illegal")

获取当前请求路径

var href = location.href

if(href.indexOf("baidu")>-1){

//跳转

location.href = "http://baidu.com"

}