获取主机域名

function getHost(url){
  var host = null;
  if(typeof url=="undefined" || null == url){
    url=window.location.href;
  }

  var regex = /^\w+\:\/\/([^\/]*).*/;
  var match = url.match(regex);
  if(typeof match !="undefined" && null != match){
    host = match[1];
  }

  return host;
}

posted on 2017-03-13 10:21  vsmart  阅读(114)  评论(0编辑  收藏  举报