0

I am trying to create a campaign page that gest redirected to from the home page just on the first enter on the website using a cookie that gets deleted when the browser is deleted but i can't figure out how to return a 302 status code to not affect my SEO. Or does this way of redirect not affect SEO and there should be no problem. This is my code

<html>
<head>

    <title></title>
    <meta charset="utf-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://example.com/splash/js/cookie.js"></script>
<script type="text/javascript">

$(function() {
    var COOKIE_NAME = 'isOnBoardingCompleted';
    var OnBoarded = Cookies.get(COOKIE_NAME);
    if (!OnBoarded) {
        Cookies.set(COOKIE_NAME, true);
        // send to on-boarding screen

        window.location = "https://www.example.com/campaign";

    }
});
</script>
</head>
<body></body>
</html>
Ciprian
  • 95
  • 1
  • 10
  • Short answer, you can't return HTTP Status codes from JavaScript, they have to come from the web server! – phuzi Oct 26 '20 at 10:07
  • 1
    From the description [sessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) might be an option. – Lain Oct 26 '20 at 10:09
  • @Lain i looked over sessionStorage but that is just for creating a sort of cookie. if i use ` window.location = "https://www.example.com"` the http status code is 301 but i need 302 – Ciprian Oct 26 '20 at 10:30
  • 1
    Does this answer your question? [Can I change the page's HTML status code on the client side?](https://stackoverflow.com/questions/4508913/can-i-change-the-pages-html-status-code-on-the-client-side) – Lain Oct 26 '20 at 10:31
  • @Lain Another idea i had was to check if useragent is bot and if it is one don't run window.location. Would that work ? – Ciprian Oct 26 '20 at 11:18

0 Answers0