Comments (13)
I ran across this article which links to an "improved version" of the plugin that adds multiple cookie functionality. http://jquery-howto.blogspot.com/2010/09/jquery-cookies-getsetdelete-plugin.html#jQuery-Cookie-plugin
from jquery-cookie.
My issue deals with more of getting all the cookie values. Say for example if the user didn't know which cookies he or she wanted, or if he or she just wanted to inspect all of them.
from jquery-cookie.
Whoops! Sorry, I accidentally closed the issue.
from jquery-cookie.
Still struggling to find a real use case for this. If you need to know whether a cookie exists or not you can just check
$.cookie('foo') === null
from jquery-cookie.
@sunjay03 "Say for example if the user didn't know which cookies he or she wanted, or if he or she just wanted to inspect all of them."
In Chrome, for example, in the Resources tab of the inspection panel there is an expandable heading for Cookies, where you can view all the cookie data associated with the current domain. Does this address the issue you mention?
from jquery-cookie.
Here is a real example:
You are writing a script which deals with saving page settings for the user. Instead of writing a million lines of code to find each setting individually, you decide to save each setting with a certain prefix:
var PREFIX = "p_setting_";
// example: save each setting individually (where the values would be found through the user's input or something
$.cookie(PREFIX+"background-color", "blue");
$.cookie(PREFIX+"background-image", "someimage.png");
$.cookie(PREFIX+"font-family", "Verdana");
// etc.
// if $.cookie() supported returning an object with all the names and values, it would be easy to load the settings back into the page.
$.each($.cookie(), function(setting, value) {
if (setting.substr(0, PREFIX.length) === PREFIX) {
$('body').css(setting.substr(PREFIX.length), value);
}
});
// Where as the alternative:
$('body').css("background-color", $.cookie(PREFIX+"background-color"));
$('body').css("background-image", $.cookie(PREFIX+"background-image"));
$('body').css("font-family", $.cookie(PREFIX+"font-family"));
// etc.
// This example may not look very hard, but as the number of settings get larger, this method would get very tedious.
This use case demonstrates the power of adding the functionality of having either an object or a multidimensional array returned as the result of an empty $.cookie() call. It would allow for quick iteration of all values and in cases like this, more optimized code.
from jquery-cookie.
I don't know why it keeps closing the issue. Sorry about that.
from jquery-cookie.
@sunjay03: there are two forks which do this. benz303 did the work, and I merged his $.cookie() work in with another bug fix from sidereel. If you want to checkout my fork: https://github.com/pboling/jquery-cookie
from jquery-cookie.
Another use case is clearing of cookies. One may want to have some kind of killer function that deletes all cookies (or at least all with a certain prefix)
from jquery-cookie.
This batch read, and the corresponding batch write:
$.cookie({ "object": "with", "cookies": "to", "set": "or", "delete": null });
...are implemented in pull request #123
from jquery-cookie.
I've implemented a version of this (https://github.com/muxa/jquery-cookie) - $.cookie() returns an array of cookie names. Pull request pending (#129).
Update: tests added
from jquery-cookie.
I believe the use case @sunjay03 brought up is now fulfillable with the newly added json support, and I believe in a technically superior way even (just keep all of the belonging properties in a single object that gets serialized to the cookie).
Regarding the "clear all cookies" use case I'm probably going to merge @muxa's PR (#129).
from jquery-cookie.
from jquery-cookie.
Related Issues (20)
- If the cookie time is up, then the cookie value is what? undefind or null? HOT 1
- Line Break HOT 1
- Line Break HOT 9
- Request - version bump on js files or revert master HOT 12
- [NuGet] Align naming convention between minified and base .js files in package HOT 2
- $.removeCookie is not deleting cookie in Chrome HOT 13
- A Session Cookie not working HOT 8
- Cookies deleted when page open without query parameters HOT 2
- $.removeCookie is not a recognized on Chrome HOT 7
- Cookie gets restored magically after some time HOT 7
- Disable issues? HOT 2
- Escape # char
- Cookie not set in IE10 HOT 1
- Do not create an issue here! HOT 3
- Bower crashing if using jquery-cookie 1.4.1 HOT 2
- Unable to install using Bower HOT 6
- Fail update cookie? HOT 2
- jquery cookie support for http flag true HOT 2
- Cookie Https HOT 2
- suggestion: add function for parse signedcookies in next rev HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-cookie.