0

I need to open a site on chrome but I need to change a cookie (SERVERID) to a particular id. Using html and JavaScript seems to be the most viable option from what I can tell.

I wanted to set the set the cookie then try launch the website in the same document. Below is my code:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" > 
                   document.cookie = "SERVERID=VENSWEB6;path=/";        
            document.location.replace('www.urlofwebsite.com');         
        </script>       
    </head>
</html>

I tried to set the cookie after replacing it; nothing changes.

I tried the line : document.cookie = "SERVERID=VENSWEB6;path=/"; on the console of the developer tool on chrome and it worked. It changed the SERVERID cookie value. So the actual code works, it's the execution that I'm struggling at.

screenshot of the developer console

Thanks in advance

Sulav

sulav.rai
  • 1
  • 1
  • Does this answer your question? [Can't access cookies from document.cookie in JS, but browser shows cookies exist](https://stackoverflow.com/questions/17508027/cant-access-cookies-from-document-cookie-in-js-but-browser-shows-cookies-exist) – Ivar Dec 09 '21 at 10:44
  • Are you trying to set a cookie for a domain other than the one you've loaded your page from? That won't work: [Setting cookies to foreign domains will be silently ignored](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie). – Richard Deeming Dec 09 '21 at 11:30
  • When I state the domain I want to set Cookie in, it doesn't make difference. – sulav.rai Dec 09 '21 at 15:42

0 Answers0