So I want my page to redirect to a different page when the user refreshes the page. I want the user to be redirected to index.html
from gettingstarted.html
when he/she refreshes the page.
CODE:
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
//meta, seo stuff
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
//body stuff
//below is just a script that redirects to gettingstarted.html upon first visit
<script type="text/javascript">
function redirect(){
var thecookie = readCookie('doRedirect');
if(!thecookie){window.location = 'http://domain.tld/gettingstarted.html';
}}function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name){var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}window.onload = function(){redirect();createCookie('doRedirect','true','999');}
</script>
</body>
gettingstarted.html
Pretty much the same thing as index.html
I tried Googling but I kept getting the “Meta Refresh Tag” which in this case, is useless.
2
Answers
Well..You can do it something like this way as :
If the first one doesn’t work so try this one as :
This will do what you’re asking, just customize the URL.
See:
See: Check if page gets reloaded or refreshed in Javascript