SwfStore
=======
SwfStore is a JavaScript library for cross-domain flash cookies. It includes a .swf file that handles the
storage and a JavaScript interface for loading and communicating with the flash file.
Working example: https://nfriedly.github.io/Javascript-Flash-Cookies/ and http://nfriedly.com/stuff/swfstore-example/
[![Bower package](http://badge.fury.io/bo/javascript-flash-cookies.svg)](http://bower.io/search/?q=flash%20cookies)
[![Build Status](https://travis-ci.org/nfriedly/Javascript-Flash-Cookies.svg?branch=master)](https://travis-ci.org/nfriedly/Javascript-Flash-Cookies)
---
Security Warning
----------------
The default storage.swf allows any website to read the data in your flash file. You should avoid storing private
information in it. It would be wise to edit and recompile the flash file to limit itself to your domain and http/https settings. (See [src/Storage.as around line 93](https://github.com/nfriedly/Javascript-Flash-Cookies/blob/master/src/Storage.as#L93).)
You can do this yourself with Adobe Flash or the Apache Flex SDK (free) or I can do it for you for $5 - email me for details.
Also, versions older than 1.9.1 are vulnerable to a XSS attack and should not be used.
Compatibility
--------------
[![Selenium Test Status (It also should work in older IE and Safari's, but the tests don't.)](https://saucelabs.com/browser-matrix/jsfc.svg)](https://saucelabs.com/u/jsfc)
Requires Flash Player 9.0.31.0 or newer. Should be compatable with nearly all desktop browsers, assuming the user has Adobe Flash installed (or it's Google Chrome, which has flash player built in). Very few mobile browsers/devices support flash.
Installation
-------------
Via [Bower](http://bower.io/):
bower install --save flash-cookies
Or install via [npm](https://npmjs.com/) (for use with [browserify](https://www.npmjs.com/package/browserify):
npm install --save flash-cookies
Usage Notes
-----------
Ensure that the `storage.swf` file is available, Browserify won't make it public by default.
Certain built-in keys such as `hasOwnProperty` cannot be overwritten in actionscript. A future version may detect this and throw an error.
Most mobile devices will not work due to lack of flash support.
Basic Usage
-----------
```javascript
// this should run on DOMReady, or at least after the opening <body> tag has been parsed.
var mySwfStore = new SwfStore({
namespace: "my_cool_app",
swf_url: "//example.com/path/to/storage.swf",
onready: function() {
mySwfStore.set('key', 'value');
console.log('key is now set to ' + mySwfStore.get('key'));
},
onerror: function(err) {
console.error(err.message);
}
});
```
A more thorough example is also available at http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/
Configuration options
---------------------
* **`swf_url`**: URL to included `storage.swf` file. All sites/pages using SwfStore should have the exact same url here for cross-domain usage, and it should be a protocol-relative url (just // instead of http:// or https://) for cross-protocol usage.
* **`namespace`**: Namespace used both internally for the JS object and for the LocalStorage Object (cookie). May contain forward slash (`/`) but all other special characters will be replaced with `_`
* **`debug`**: Set to true to log debug information to the browser console (Automatically creates a logging `<div>` on the page if no console is available.)
* **`timeout`**: Number of seconds to wait before concluding there was an error. Defaults to `10`.
* **`onready`**: Callback function to fire once SwfStore is loaded and ready. No arguments.
* **`onerror`**: Callback function to fire in the event of an error. Passes an `Error` object as the first argument.
API
---
Instance methods:
* **`get(key)`**: Returns the value for `key` as a String or `null` if the key is not set.
* **`set(key, value)`**: Sets `key` to `value`.
* Note: setting a `key` to `null` or `undefined` is equivalent to `clear()`ing it.
* **`clear(key)`**: Deletes the value for `key` if it exists.
* **`getAll()`**: Returns a Object in the form of `{key: value}` with all data stored in the .swf.
* **`clearAll()`**: Clears all data from the .swf.
* **`ready`**: Boolean to indicate whether or not the .swf has loaded and is ready for access.
* Note: providing an `onready` callback to the config is recommended over checking the `.ready` property.
Troubleshooting
---------------
* Be sure the urls to the .swf file and .js file are both correct.
* If the .swf file is unable to communicate with the JavaScript, it will display log messages on the flash object. If debug is enabled, this should be visible on the page.
* To hide the flash object and disable the log messages appending to the bottom of the page, set `debug: false` in the configuration options. (Log messages are added to a `<div>` if no browser `console` is available).
* If the user does not have flash installed, the onerror function will be called after a (configurable) 10 second timeout. You may want to use a library such as [Flash Detect](http://www.featureblend.com/javascript-flash-detection-library.html) to check for this more quickly. Flash Player 9.0.31.0 or newer is required.
* If you pass a non-string data as the key or value, things may break. Your best bet is to use strings and/or use JSON to encode objects as strings.
* If you see the error `uncaught exception: Error in Actionscript. Use a try/catch block to find error., try using // in the .swf URL rather than https://. See https://github.com/nfriedly/Javascript-Flash-Cookies/issues/14 for more information.
* Do not set display:none on the swf or any of its parent elements, this will cause the file to not render and the timeout will be fired. Disable debug and it will be rendered off screen.
* The error this.swf.set is not a function has been known to occur when the FlashFirebug plugin is enabled in Firefox / Firebug.
* This library is not sutable for storing large amounts of data because the .swf is normally rendered off screen and thus there is no way for the user to respond to Flash's prompt to increase the storage limit.
File Details
------------
storage.swf is the compiled flash file ready to be embedded in your website. Note the security warning above.
swfstore.min.js - a copy of swfstore.js, minified for your convenience. This and a copy of storage.swf should
be all you need to use this on a production website.
swfstore.js handles the interaction between javascrpt and flash, it also handles embedding and some basic error
checking.
Storage.as is where all the magic happens. It maps an External Interface to a Local Storage Object. I'm no expert when it comes to Flash / ActionScript, but it should be reasonably well documented and fairly safe.
The storage.fla is essentially just an empty shell file that points to Storage.as as it's main class.
See example/index.html for a working example that you can put on your site.
Compiling
---------
### .js
This project uses [UglifyJS2](https://github.com/mishoo/UglifyJS2) via the [Grunt](http://gruntjs.com/) plugin. Setup:
* Install [Node.js](http://nodejs.org/)
* Install Grunt globally: `npm install -g grunt`
* `cd` into the project directory and install the dependencies: `npm install`
* Run `grunt uglify` to "compile" (minify) the JavaScript.
### .swf
This .swf can be compiled using Adobe Flash (paid) or the Apache Flex SDK (free).
With Adobe Flash, open `src/storage.fla` and export it to `dist/storage.swf`
Grunt is set up to use Apache Flex via the [grunt-swf](https://github.com/nfriedly/grunt-swf) plugin.
The plugin is installed via the standard `npm install` but the SDK must be installed separately.
See `flex-sdk/instructions.md` or https://github.com/nfriedly/grunt-swf#installing-the-apache-flex-sdk for more details on installing the Flex SDK.
Then run `grunt swf` to compile the .swf.
Tip: `grunt build` will compile both the .js
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
对于写网站时需要跨域和跨浏览器的可以看看这个。 引入jquery 和 swfstore.min.js 就可以了,蛮简单好用的,会jquery基础就可以咯。 mySwfStore.set('myKey', '值'); //设置flashcookie mySwfStore.get('myKey'); //读取flashcookie 还有清除等命令在例子里,大家可以自己看哦。 跨域只需要把 js代码里的 swf_url 地址设置成绝对地址就可以了。 比如 swf_url=http://www.a.com/storage.swf ,那么在b.com上面就能对a站的flashcookie进行读写了。 因为他的storage.swf文件默认可以跨域、如果需要关闭,请重新编译源码。
资源推荐
资源详情
资源评论
收起资源包目录
nfriedly-Javascript-Flash-Cookies-v2.2.1-16-gb6c6c54.zip (24个子文件)
nfriedly-Javascript-Flash-Cookies-b6c6c54
.travis.yml 284B
example
index.html 3KB
package.json 1KB
readme.md 10KB
tests
spec-runner.html 3KB
spec
flashcookies-spec.js 8KB
lib
jasmine-2.0.3
jasmine-html.js 12KB
jasmine.css 19KB
console.js 4KB
jasmine_favicon.png 1KB
boot.js 5KB
jasmine.js 67KB
jasmine-jsreporter.js 13KB
dist
storage.swf 2KB
swfstore.min.js 4KB
Gruntfile.js 5KB
src
Storage.as 11KB
swfstore.js 12KB
storage.fla 5KB
.gitignore 74B
history.md 5KB
flex-sdk
instructions.md 304B
.jshintrc 109B
bower.json 841B
共 24 条
- 1
资源评论
- 尼尾拉于2018-01-07请问,用于跨浏览器时,数据保存在硬盘中的什么位置呢
- 风平-浪静2019-01-01清空浏览器Cookie后,值也相应的清空了
jiahuafu
- 粉丝: 15
- 资源: 37
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功