Computer >> Computer tutorials >  >> Programming >> Javascript

How to return the protocol (http or https) of the web page with JavaScript?


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>