Javascript String getHost(url)

Description

Javascript String getHost(url)


function getHost(url) {
    var host = "null";
    if (typeof url == "undefined" || url = null) {
        url = window.location.href;
    }//w ww.  jav a  2  s  . c o m
    var regex = /^\w+\:\/\/([^\/]*)/;
    var match = url.match(regex);
    if (typeof match != "undefined" && match != null) {
        host = match[1];
    }
    return host;
}



PreviousNext

Related