jQuery Cookie不工作在IE 8? [英] jQuery Cookie Not Working in IE 8?

查看:187
本文介绍了jQuery Cookie不工作在IE 8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑: 我在下面的cookie有问题,所以我切换到jQuery Cookie,仍然的错误持久,所以我发布了jQuery Cookie代码在这里,原始问题完整:



在一个页面上,我调用colorbox并且该代码在另一个页面上正常工作我改变了cookie名称和函数调用, :

  var $ j = jQuery.noConflict(); 
$ j(window).load(function(){
//我也试过了 - $ j(document).ready(function(){ -
///改变了任何东西

if(!$ j.cookie('homecookie')){
$ j(#start)。click();

//点击函数点击一个隐藏的链接witch触发一个fancybox
//灯箱加载 - 除了IE(已测试8),其中所有的工作正常在其中
//灯箱继续加载,不管cookie

$ j.cookie(homecookie,1,{expires:30,path:'/'});
}
});

如何让这在IE 8+中工作 - 页面加载时不会抛出错误,参考:



本页首次访问时应触发Fancybox只有



注意:我在FF,Chrome,Safari和Opera上测试了上述Cookie /脚本,所有工作都很好。






--------原始问题-------- p>

我使用以下cookie:

  var $ j = jQuery。 noConflict(); 

$ j(document).ready(function(){

if(document.cookie.indexOf('visited = true')== -1)
{
var thirtyDays = 1000 * 60 * 60 * 24 * 30;
var expires = new Date((new Date())valueOf()+ thirtyDays);
document.cookie =visited = true; path = /; expires =+ expires.toUTCString();
$ j.colorbox({inline:true,href:#gallery-nav-instruct});
}

});

它可以在FF和Chrome中使用,但不能在IE 8中使用。



设置中允许使用Cookie。



有一些问题,在一个页面上,脚本不是由IE(Colorbox)在另一个页面上触发的,Cookie不会被重新聚合,脚本不断被调用。只有改变两个脚本改变 $ j.colorbox({inline:true,href:#gallery-nav-instruct}); $ j(#start)。click();

解决方案

Fancybox是这个问题。我切换到colorbox和使用jQuery Cookie它工作正常的页面我有一个问题,但它在另一个有些不同的网页上创建了另一个问题



以下是工作代码:

  var $ j = jQuery.noConflict(); 
$ j(window).load(function(){
if(!$ j.cookie('homecookie')){
$ j.colorbox({inline:true,href: #home-welcome});
$ j.cookie(homecookie,1,{expires:30});
}
}


EDIT: I was having an issue with the cookie below so I switched to jQuery Cookie and still the error persist so I posted the jQuery Cookie code here but left my original question intact:

On one page I call colorbox and that code works properly yet on another page I changed the cookie name and function called and it breaks, here is that code:

var $j = jQuery.noConflict();
$j(window).load(function() {
//I have also tried - $j(document).ready(function(){ - 
///to see if that changed anything

if(!$j.cookie('homecookie')){
$j("#start").click(); 

//the click functions clicks a hidden link witch triggers a fancybox 
//lightbox to load - works properly in all but IE (have tested 8) in which
//the lightbox continues to load regardless of the cookie

$j.cookie("homecookie", 1, {expires: 30, path: '/'});
}
});

How can I get this to work in IE 8+ - No errors are thrown when the page loads. Here is the page in reference:

This Page Should Trigger Fancybox on First Visit Only

Note: I have tested the above cookie/script in FF, Chrome, Safari, and Opera and all work fine.


--------Original Question--------

I am using the following cookie:

var $j = jQuery.noConflict();

$j(document).ready(function(){

   if (document.cookie.indexOf('visited=true') == -1) 
   {
      var thirtyDays = 1000*60*60*24*30;
      var expires = new Date((new Date()).valueOf() + thirtyDays);
      document.cookie = "visited=true;path=/;expires=" + expires.toUTCString();
      $j.colorbox({ inline:true, href:"#gallery-nav-instruct"});
   }

});

It works in FF and Chrome but not in IE 8.

Cookies are allowed in the settings.

There are a couple issues, on one page the script is not triggered by IE (Colorbox) on another page the cookie is not reconizged and the script keeps getting called. Only change in the two scripts is changing the $j.colorbox({ inline:true, href:"#gallery-nav-instruct"}); to $j("#start").click();

解决方案

It appears that Fancybox was the issue. I switched to colorbox and using jQuery Cookie it works fine on the page I was having an issue yet it created another issue on another page that is a bit different.

Here is the code that worked:

var $j = jQuery.noConflict();
$j(window).load(function() {
if(!$j.cookie('homecookie')){
$j.colorbox({ inline:true, href:"#home-welcome"});
$j.cookie("homecookie", 1, {expires: 30});
}
});

这篇关于jQuery Cookie不工作在IE 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆