Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách trả về giao thức (http hoặc https) của trang web với JavaScript?

Sử dụng window.location.protocol để lấy giao thức của trang hiện tại (http: hoặc https:).

Ví dụ

<!DOCTYPE html>
<html>
  <body>
    <script>
      document.write("Giao thức: <br>Giao thức là: " + window.location.protocol);
    </script>
  </body>
</html>