Files
30-seconds-of-code/snippets/getProtocol.md
2020-10-08 15:24:58 +03:00

302 B

title, tags
title tags
getProtocol browser,beginner

Returns the protocol being used on the current page.

  • Use window.location.protocol to get the protocol (http: or https:) of the current page.
const getProtocol = () => window.location.protocol;
getProtocol(); // 'https:'