solvit.io

Detect with JavaScript if the current web page uses HTTPS

Solution
function isSecure()
{
    return 'https:' == window.location.protocol;
}

var usesHttps = isSecure();
Example
// ...
var usesHttps = isSecure();

// if page = https://example.org -> usesHttps = true
// if page = http://example.org  -> usesHttps = false
Find more solutions about: ,