How to Create a Broadcast Bar with Cookies

August 16, 2018 comments 117 Reads

Hi, My name is Andy Leverenz and I work as a Product Designer at Dribbble. For fun I design, code, and write. Check out my blog called Web-Crunch where I publish design and development tutorials with the occasional vlog.
I’m back at it with the Let’s Build: With JavaScript series. In this video learn how to build a broadcast bar with cookies using vanilla JavaScript and some elbow grease.
This particular example utilizes some browser technologies to create a cookie for any user who navigates to your page and closes a broadcast banner. If they did indeed click the “X” icon, a cookie gets stored for 7 days in their browser.
This solution isn’t foolproof as a user can just clear their cookies to see the broadcast bar again, but it does allow you to leverage storing something without needing a user to be signed in to some sort of session.