Use window.location.protocol
to check if it is https:
function isSecure()
{
return window.location.protocol == 'https:';
}
Alternatively you can omit specifying "window" if you don't have a locally scoped location.
function isSecure()
{
return location.protocol == 'https:';
}
As google analytics taught me:
if ("https:" == document.location.protocol) {
/* secure */
} else {
/* unsecure */
}
Second method for newest browsers:
var secure = window.isSecureContext;
or just get isSecureContext:
if (isSecureContext) {
...
}
More here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#Feature_detection#Feature_detection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With