Is it possible to detect, on the client side, whether the user is using an encrypted page or not?
Put another way -- I want to know if the URL of the current page starts with http or https.
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:';
}
Second method for newest browsers:
var secure = window.isSecureContext;
or just get isSecureContext:
if (isSecureContext) {
...
}
http://localhost and file:// paths are considered to have been delivered securely."window.isSecureContext == true but the browser is saying "Not Secure" due to the certificate being invalid. Is there any way to check the page has the "closed lock" with no warnings?