Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> </head> <body> <script> // special characters (spaces), need encoding let name = "firstname lastname"; let value = "Jack Down" // encodes the cookie as firstname%20lastname=Jack%20Down document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value); alert(document.cookie); // ...; firstname%20lastname=Jack%20Down </script> </body> </html>