How to run JavaScript code stored as a string in a web-browser-cookie?

I am trying to create a web browser cookie with JavaScript.
The cookie is created in page A but the JavaScript code in it should run only in Page B.

document.cookie = "alert('Hi');"
let x = document.cookie;
console.log(x);

How to create a cookie like I need here?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.