Get current page protocol in JavaScript

Description

The following code shows how to get current page protocol.

Example


<!--from w  w w .j  ava2 s .  c o m-->
<!DOCTYPE HTML>
<html>
<body>
<script>
document.writeln("protocol: " + document.location.protocol);
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get current page protocol in JavaScript