Update snippet descriptions

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-19 22:49:51 +03:00
parent 40a411f5b8
commit 920a0c390b
41 changed files with 94 additions and 81 deletions

View File

@ -3,11 +3,12 @@ title: httpsRedirect
tags: browser,intermediate
---
Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history.
Redirects the page to HTTPS if it's currently in HTTP.
- Use `location.protocol` to get the protocol currently being used.
- If it's not HTTPS, use `location.replace()` to replace the existing page with the HTTPS version of the page.
- Use `location.href` to get the full address, split it with `String.prototype.split()` and remove the protocol part of the URL.
- Note that pressing the back button doesn't take it back to the HTTP page as its replaced in the history.
```js
const httpsRedirect = () => {
@ -16,5 +17,6 @@ const httpsRedirect = () => {
```
```js
httpsRedirect(); // If you are on http://mydomain.com, you are redirected to https://mydomain.com
httpsRedirect();
// If you are on http://mydomain.com, you are redirected to https://mydomain.com
```