比如说.在JSP中可以这样实现 ,
<%   
  Response.Cookies("MyCookle").Domain="google.com"   
  %>   
但在javascript怎么来实现呢??

解决方案 »

  1.   

    cookieString   =   cookieString   +   ";   expire= "   +   date.toGMTString(); 
    ==>
    cookieString   =   cookieString   +   ";   expire= "   +   date.toGMTString()+";domain="+Domain; 
    不能将一个cookie的域设置成服务器所在的域之外的域.

    aaa.xxx.com
    bbb.xxx.com
    是可以的但
    aaa.google.com就不行了
      

  2.   

    比如说.在JSP中可以这样实现   ,
    <%      
        Response.Cookies( "MyCookle ").Domain= "google.com "      
        %>      
    但在javascript怎么来实现呢?? 你可以用<script type="text/javascript">
    document.domain = "google.com";
    </script>ResThe property initially returns the host name of the server from which the page is served. The property can be assigned the domain suffix to allow sharing of pages across frames. For example, a page in one frame from home.microsoft.com and a page from www.microsoft.com initially would not be able to communicate with each other. However, by setting the domain property of both pages to the suffix "microsoft.com", you ensure that both pages are considered secure and access is available between the pages. When you set the domain property, use the domain name determined by the server rather than by the client browser. All the pages on different hosts must have the domain property explicitly set to the same value to communicate successfully with each other. For example, the value of the domain property of a page on the host microsoft.com would be "microsoft.com" by default. It might seem logical that if you set the domain property of a page on another host named msdn.microsoft.com to "microsoft.com," that the two pages could communicate with each other. However, this is not the case unless you have also explicitly set the domain property of the page on microsoft.com to "microsoft.com". Furthermore, this property cannot be used to allow cross-frame communication among frames with different domain suffixes. For example, a page in one frame from www.microsoft.com and a page in another frame from www.msn.com would not be able to communicate with each other even if the domain property of both pages was set to the suffix "microsoft.com".
      

  3.   

    也可以在调用方法上想办法,比如直接写入URL
      

  4.   

    上周研究了半天。发现其实这个问题可以这样来解决的。
    //添加cookie 
    function   addFundCookie(name,   expireHours)   { 
    var   fundValue   =   rewriteCookieValue(); 
    var   cookieString   =   name   +   "= "   +   escape(fundValue); 
    if   (expireHours   >   0)   { 
    var   date   =   new   Date(); 
    date.setTime(date.getTime()   +   expireHours   *   3600   *   1000); 
    cookieString=cookieString+"; expire="+date.toGMTString()+ ";path=/;domain=.google.com";

    document.cookie   =   cookieString; 
    } 我在查看google所用的cookie得到的启发。
    cookieString=cookieString+"; expire="+date.toGMTString()+ ";path=/;domain=.google.com";
    需要加上path谢谢各位了。