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

HTMLJavascriptProgramming Scripts

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>
raja
Published on 26-Feb-2018 14:56:32
Advertisements