Browser Info Cookie
Capture the visitor's environment. This script not only remembers the user's name but also logs their specific browser details (User Agent) into a persistent cookie for future reference and site optimization.
Persistent Browser Profile
- Visitor Name Guest User
- Browser Code Loading...
- User Agent Loading...
Copy the Script
<script>
// 1. Gather Data
var visitorName = prompt("Please enter your name:", "Guest");
var browserInfo = navigator.userAgent;
// 2. Set Expiration (1 Year)
var expiry = new Date();
expiry.setTime(expiry.getTime() + (365 * 24 * 60 * 60 * 1000));
// 3. Store in Cookies (using encodeURIComponent for safety)
// Note: 'path=/' makes the cookie available across the whole site
document.cookie = "vName=" + encodeURIComponent(visitorName) + "; expires=" + expiry.toUTCString() + "; path=/";
document.cookie = "vBrowser=" + encodeURIComponent(browserInfo) + "; expires=" + expiry.toUTCString() + "; path=/";
</script>
Frequently Asked Questions
The script specifically captures the 'User Agent' string (navigator.userAgent), which typically contains the browser name, version number, and operating system.
It is useful for technical support sites or web apps that need to remember a user's environment configuration for troubleshooting purposes.
Yes, the navigator.userAgent string contains keywords like 'Android' or 'iPhone', which allows you to determine if the user is on a mobile device later when you read the cookie.