js 小工具-- 获取主机名

Posted on 2016-03-03 09:55  豌豆娃  阅读(575)  评论(0编辑  收藏  举报
   <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>

 

Copyright © 2024 豌豆娃
Powered by .NET 8.0 on Kubernetes