如何使用JavaScript返回网页的协议(http或https)?

使用window.location对象返回协议。该窗口ocation.protoco L将返回网络协议,即无论是HTTP HTTPS -

示例

<!DOCTYPE html>
<html>
   <body>
      <script>
         document.write("https or https: <br>The protocol is:"+window.location.protocol);
      </script>
   </body>
</html>