How can I use JavaScript on the client side to detect if the page was encrypted?

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:';
}

Leave a Comment