js 小工具-- 获取主机名

   <script type="text/javascript">
    function getHostName(url) {
        var host = "null";
        if (typeof url == "undefined" && null == url) {
            url = window.location.href;
        }
        var reg = /^w+://([^/]*.*)/;
        var match = url.match(reg);
        if (typeof match != "undefined" && null != match) {
            host = match[1];
        }
        return host;
    }
 
    </script>
原文地址:https://www.cnblogs.com/benbenhuan/p/5237421.html