Get all cookies with Javascript

by | Dec 18, 2017 | Blog | 9 comments

Its very common that we all still use HTTP or HTTPS cookies for storing various data on visitor’s browser. But in HTML5 , you can use local storing various data . I’m talking about the old school for getting all the cookies using the Javascript . Here as we still have old browsers to take care of the cookies. The jQuery Cookie plugin (http://plugins.jquery.com/project/Cookie) is useful for getting the value of cookies when you already know the name of the cookies you want to query from the browser, but provides no way to get a list of all the cookies that are set already. The following Javascript function loads them all into an associative array with the cookie name as the index and the cookie value as the value: function get_cookies_array() { var cookies = { }; if (document.cookie && document.cookie != ”) { var split = document.cookie.split(‘;’); for (var i = 0; i < split.length; i++) { var name_value = split[i].split(“=”); name_value[0] = name_value[0].replace(/^ /, ”); cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]); } } return cookies; } var cookies = get_cookies_array(); for(var name in cookies) { console.log( name + ” : ” + cookies[name] + “ ” ); } You could then get the cookies and write them out into the document like so: var cookies = get_cookies_array(); for(var name in cookies) { document.write( name + ” : ” + cookies[name] + “<br />” ); } You can access cookie information in javascript using document.cookie function, but you will only be able to read the cookies that are on the same domain that the script is being run.  

Enhance Customer Engagement and Interaction with Google My Business

Why Your Business Needs Google My Business? Having a Google Business Profile is like having a virtual shopfront that people see when they search for your business online. It helps you build trust and credibility with your customers. With a well-optimized profile, you...

The Ultimate Guide to Responsive Image Optimization

Leveraging HTML Picture Element for Responsive Images In the ever-evolving landscape of web development, creating responsive websites that cater to a variety of devices and screen sizes is crucial. One key aspect of responsiveness is optimizing images for different...

The Impact of Design on Achieving Web Development Success

Design: The Key Element in Successful Web Development When it comes to web development, there are many aspects that need to be taken into consideration in order to create a successful website. One of the most vital parts of web development is designing. Designing...

Selecting a Web Design Firm for Your Business: A Guide to Success

Getting Around the Digital Maze: Selecting the Best Web Design Firm for Your Enterprise Today, choosing a web design firm is a crucial choice that may have a significant influence on your organization in the ever-changing world of online presence. A well-designed...

Website Design Ideas for a Successful Website

7 WEBSITE DESIGN IDEAS TO CREATE A RESULTING WEBSITE These days, having an online presence is crucial for businesses of all sizes. It’s no secret that a website serves as potential customers’ first impression of your company, therefore making a good first...

Testing and Debugging Website Development

Tools and Techniques for Testing and Debugging Website Development in 2024 In the fast-paced world of website development, staying ahead of the curve is crucial to delivering high-quality, reliable websites. Testing and debugging are essential steps in the development...

Why Google Ads are Crucial for Your Business Growth?

Discover the Top Reasons Why Google Ads are Crucial for Your Business Growth Looking to boost your online presence? Discover why Google Ads are essential for your business. Read our blog for the top reasons. Google Ads, formerly known as Google Ad Words, is a powerful...