Use the window.location object to return the protocol. The window.location.protocol will return the web protocol i.e. whether it’s http or https −
Example
<!DOCTYPE html>
<html>
<body>
<script>
document.write("https or https: <br>The protocol is:"+window.location.protocol);
</script>
</body>
</html>