Pregunta

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();

¿Fue útil?

Solución 2

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});
}
});

Otros consejos

Are you able to try this code? Does it work better?

https://developer.mozilla.org/en/DOM/document.cookie

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top