2009-12-23

Flash取得Cookie

當然還是得透過 JavaScript 才會取得, 不過可以偷懶不用寫 JavaScript:

var s:String = ExternalInterface.call("document.cookie.toString");

通常會處理一下

var cookieStr:String = ExternalInterface.call("document.cookie.toString");
var cookieObj:Object = {};
cookieStr = cookieStr.split(' ').join('');
var tmp:Array = cookieStr.split(';');
for(var i in tmp) {
var tmp2:Array = tmp[i].split('=');
cookieObj[tmp2[0]] = unescape(tmp2[1]);
}
s_txt.text = cookieObj['PHPSESSID'];

沒有留言:

FB 留言