本地创建一个测试a.html文件,用ifame包含一个其他域名下有cookie操作的文件b.html当直接访问b.html时,所有cookie操作均有效。
当访问a.html时,iframe中b.html的getcookie,deletecookie都有效,setcookie失效。测试环境包括 ie6,ie7,ie8,firefox3.5,其中ie8,firefox3.5正常,ie6,ie7出现以上问题。请知道的给予解答。
谢谢先

解决方案 »

  1.   

    测试代码中使用了jquerya.html<html>
    <head>
    <title></title>
    </head>
    <body>
    <iframe src="http://www.xxx.com/b.html"></iframe>
    </body>
    </html>
    b.html<html>  
    <head>
    <title></title>
    <script type="text/javascript" src="js/jquery.js"></script>
    </head><body>
    <script language="javascript">
    jQuery.cookie = function(name, value, options) {
      if (typeof value != 'undefined') {
      options = options || {};
      if (value === null) {
      value = '';
      options.expires = -1;
      }
      var expires = '';
      if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
      var date;
      if (typeof options.expires == 'number') {
      date = new Date();
      date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
      } else {
      date = options.expires;
      }
      expires = '; expires=' + date.toUTCString();
      }
      var path = options.path ? '; path=' + (options.path) : '';
      var domain = options.domain ? '; domain=' + (options.domain) : '';
      var secure = options.secure ? '; secure' : '';
      document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
      } else {
      var cookieValue = null;
      if (document.cookie && document.cookie != '') {
      var cookies = document.cookie.split(';');
      for (var i = 0; i < cookies.length; i++) {
      var cookie = jQuery.trim(cookies[i]);
      if (cookie.substring(0, name.length + 1) == (name + '=')) {
      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
      break;
      }
      }
      }
      return cookieValue;
      }
    };var n = "test";
    var v = parseInt($.cookie(n));
    if (v==null || isNaN(v)) v = 0;
    $.cookie(n, v+1);
    document.write(v+1);</script>
    </body>
    </html>
      

  2.   

    该问题出现在页面分享到qqzone时,不知怎么解决。求助达人解决
      

  3.   

    跨域问题吧,a没有权限访问b的cookie
      

  4.   

    应该是P3P可以解决吧。。
    但是我在head中加入 <meta http-equiv="P3P" content='CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"'> 却是无效。。我用的是php,如果在php中设置header就有效