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>