2010-05-25 4 views
0

외부 인터페이스를 사용하여 응용 프로그램의 클라이언트 측에 쿠키를 저장하고 있습니다. 마찬가지로 html로 쿠키를 만든 및 Flex 외부 인터페이스를 사용하여 이러한 메서드를 사용하고 있습니다. 나는 쿠키를 사용하여 쿠키를 표시 할 때 쿠키를 사용자 이름으로 저장하고 있는데, 서버에 배포 한 후 http://localhost/[Path]/index.html.in이 html 임베디드 swf 파일이고 쿠키를 html JavaScript에 저장했습니다. 이제이 URL 쿠키를 열면 쿠키가 저장됩니다. 새로운 창을 열면 쿠키가 올라가서 처음부터로드됩니다. 내가 플렉스에서이 코드를 사용하고 저장하는 쿠키 :이 var anotherCookie:Cookies = new Cookies("username"); anotherCookie.value=[Textinput].text; 같은 쿠키를 사용하고내가 창 쿠키를 닫으면 플렉스가 깨져 버림

`패키지 이름 {

import flash.external.ExternalInterface; 

/** 
* The Cookie class provides a simple way to create or access 
* cookies in the embedding HTML document of the application. 
* 
*/ 
public class Cookies { 

    /** 
    * Flag if the class was properly initialized. 
    */ 
    private static var _initialized:Boolean = false; 

    /** 
    * Name of the cookie. 
    */ 
    private var _name:String; 

    /** 
    * Contents of the cookie. 
    */ 
    private var _value:String; 

    /** 
    * Flag indicating if a cookie was just created. It is <code>true</code> 
    * when the cookie did not exist before and <code>false</code> otherwise. 
    */ 
    private var _isNew:Boolean; 

    /** 
    * Name of the external javascript function used for getting 
    * cookie information. 
    */ 
    private static const GET_COOKIE:String = "cookieGetCookie"; 

    /** 
    * Name of the external javascript function used for setting 
    * cookie information. 
    */ 
    private static const SET_COOKIE:String = "cookieSetCookie"; 

    /** 
    * Javascript code to define the GET_COOKIE function. 
    */ 
    private static var FUNCTION_GET_COOKIE:String = 
      "function() { " + 
        "if (document." + GET_COOKIE + " == null) {" + 
          GET_COOKIE + " = function (name) { " + 
            "if (document.cookie) {" + 
              "cookies = document.cookie.split('; ');" + 
              "for (i = 0; i < cookies.length; i++) {" + 
                "param = cookies[i].split('=', 2);" + 
                "if (decodeURIComponent(param[0]) == name) {" + 
                  "value = decodeURIComponent(param[1]);" + 
                  "return value;" + 
                "}" + 
              "}" + 
            "}" + 
            "return null;" + 
          "};" + 
        "}" + 
      "}"; 

    /** 
    * Javascript code to define the SET_COOKIE function. 
    */ 
    private static var FUNCTION_SET_COOKIE:String = 
      "function() { " + 
        "if (document." + SET_COOKIE + " == null) {" + 
          SET_COOKIE + " = function (name, value) { " + 
            "document.cookie = name + '=' + value;" + 
          "};" + 
        "}" + 
      "}"; 

    /** 
    * Initializes the class by injecting javascript code into 
    * the embedding document. If the class was already initialized 
    * before, this method does nothing. 
    */ 
    private static function initialize():void { 
      if (Cookies._initialized) { 
        return; 
      } 

      if (!ExternalInterface.available) { 
        throw new Error("ExternalInterface is not available in this container. Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime are required."); 
      } 

      // Add functions to DOM if they aren't already there 
      ExternalInterface.call(FUNCTION_GET_COOKIE); 
      ExternalInterface.call(FUNCTION_SET_COOKIE); 

      Cookies._initialized = true; 
    } 

    /** 
    * Creates a new Cookie object. If a cookie with the specified 
    * name already exists, the existing value is used. Otherwise 
    * a new cookie is created as soon as a value is assigned to it. 
    * 
    * @param name The name of the cookie 
    */ 
    public function Cookies(name:String) { 
      Cookies.initialize(); 

      this._name = name; 
      this._value = ExternalInterface.call(GET_COOKIE, name) as String; 

      this._isNew = this._value == null; 
    } 

    /** 
    * The name of the cookie. 
    */ 
    public function get name():String { 
      return this._name; 
    } 

    /** 
    * The value of the cookie. If it is a new cookie, it is not 
    * made persistent until a value is assigned to it. 
    */ 
    public function get value():String { 
      return this._value; 
    } 

    /** 
    * @private 
    */ 
    public function set value(value:String):void { 
      this._value = value; 

      ExternalInterface.call(SET_COOKIE, this._name, this._value); 
    } 

    /** 
    * The <code>isNew</code> property indicates if the cookie 
    * already exists or not. 
    */ 
    public function get isNew():Boolean { 
      return this._isNew; 
    } 
} 

} 나는 또한 새 창에서 쿠키를 저장 사용해야 코드가 .is는? 미리 감사드립니다.

답변

0

기본적으로 브라우저는 현재 세션이 끝날 때 쿠키를 삭제합니다. 그들이 브라우저를 닫을 때. "만료"날짜를 얼마간 미래의 날짜로 설정하여 잠시 동안 머물 수 있습니다. 특정 유형의 안티 바이러스 프로그램이있는 경우 쿠키도 삭제할 수 있습니다.

관련 문제