Often time we may want to do some processes like handling payments, accessing private information, working with service workers, etc. on our web app or web page. These activities should only be done when the current web page context is secure or if the context is HTTPS
enabled
The easy way to check if the current context of a web page is HTTPS
enabled is to check using the isSecureContext
property in the window object.
// check if the current context is HTTPS enabled
const isItHTTPS = window.isSecureContext;
console.log(isItHTTPS); // true
- The property returns a boolean
true
if the current context isHTTPS
enabled andfalse
if not.
See this snippet live in JSBin.