Files
30-seconds-of-code/javascript/snippets/get-protocol.md
2023-05-01 22:35:56 +03:00

20 lines
375 B
Markdown

---
title: Current page protocol
type: snippet
tags: [browser]
cover: bamboo-lamp
dateModified: 2020-10-20T11:46:23+03:00
---
Gets the protocol being used on the current page.
- Use `Window.location.protocol` to get the protocol (`http:` or `https:`) of the current page.
```js
const getProtocol = () => window.location.protocol;
```
```js
getProtocol(); // 'https:'
```