1. 程式人生 > >js 判斷 https 還是http

js 判斷 https 還是http

function getBaseUrl() {
    var ishttps = 'https:' == document.location.protocol ? true : false;
    var url = window.location.host;
    if (ishttps) {
                url = 'https://' + url;
    } else {
          url = 'http://' + url;
    }
    return url;
}