diff --git a/snippets/httpsRedirect.md b/snippets/httpsRedirect.md new file mode 100644 index 000000000..f60a79610 --- /dev/null +++ b/snippets/httpsRedirect.md @@ -0,0 +1,9 @@ +### httpsRedirect + +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. + +```js +const httpsRedirect = () => { + if(location.protocol !== "https:") location.replace("https://" + location.href.split("//")[1]); +} +``` \ No newline at end of file