How to detect the current protocol (HTTP or HTTPS) in JavaScript

1 Answer

0 votes
if (window.location.protocol == 'http:') {
 var p = 'http:'; 
} else { 
    if (window.location.protocol == 'https:') {
        var p = 'https:'; 
    }
}

document.write(p);
 
/*
run: 
 
http:
 
*/

 



answered Jun 21, 2018 by avibootz

Related questions

1 answer 145 views
1 answer 148 views
1 answer 142 views
1 answer 170 views
2 answers 248 views
...