Why session cookie? cannot be generated with js

in chrome, run

<html>
<body>
 
<button id="cookie">test</button>
 <script>
function setCookie()
{
  document.cookie = "flag=1;expires="";path=/";
}
ob = document.getElementById("cookie");
ob.addEventListener("click",setCookie);
</script>
</body>
</html>
After the

web page is opened, cookie is generated, but after closing the web page and reopening it, the cookie is still there, not a session cookie, excuse me, how to use js to generate session cookie?

document.cookie = "flag=1;expires=0;path=/"; can"t do it

Dec.10,2021

you can create an expires as long as it is left blank. I tried to turn off the browser on my computer to remove cookie. Whether you just close the tab, only closing the tab can not remove cookie.

A better way to write:
document.cookie = "cookiename=value; expires=0; path=/";

the picture is to test your code, pay attention to the expiration time, you can see that it is correct.


whether you just closed the tab, only closing the tab can not remove cookie.
judge correctly

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e65bff-45390.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e65bff-45390.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?