流浪のwolf

卷帝

导航

从url地址获取主机名

        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;
    }
    console.log(getHost('https://i.cnblogs.com/articles'))

posted on 2022-08-24 20:27  流浪のwolf  阅读(35)  评论(0编辑  收藏  举报