您的位置:首页 > Web前端 > JavaScript

js跨域

2016-07-12 00:00 267 查看
跨域

js获取最后的顶级域名,其他都过滤掉。,指定domain域名。

<script type="text/javascript">
var getHost = function(url) {
var host = "null";
if (typeof url == "undefined"
|| null == url)
url = window.location.href;
var regex = /.*\:\/\/([^\/|:]*).*/;
var match = url.match(regex);
if (typeof match != "undefined"
&& null != match) {
host = match[1];
}
if (typeof host != "undefined"
&& null != host) {
var strAry = host.split(".");
if (strAry.length > 1) {
host = strAry[strAry.length - 2] + "." + strAry[strAry.length - 1];
}
}
return host;
}
document.domain=getHost();
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: