Question

I am using this plugin to establish a cookie

Everything works well but in IE7 & IE8

Here is my JS code:

jQuery(document).ready(function() {

    jQuery(function() {
          if (jQuery.cookie('shownDialog') != 'true') {
            window.onload = document.getElementById('lightbox-22556401244951').click(); 
          }
            jQuery.cookie('shownDialog', 'true', {expires: 7});
    });

});

Not sure why its not working in only IE7 & IE8?

Was it helpful?

Solution

You are wrapping everything in the ready function so window.onload has already fired. Update your code to this:

    jQuery(function() {
          if (jQuery.cookie('shownDialog') != 'true') {
            jQuery('#lightbox-22556401244951').trigger("click"); 
          }
            jQuery.cookie('shownDialog', 'true', {expires: 7});
    });

OTHER TIPS

The ready event normally happens before the load event, but IE doesn't have an ondomready event so jQuery emulates it. That means that the ready event sometimes can happen after the load event in IE.

Use the load method to bind the event, then it will always fire. If the load event has already fired, jQuery will call the event handler directly:

jQuery(document).ready(function() {

  jQuery(function() {
      if (jQuery.cookie('shownDialog') != 'true') {
        jQuery(window).load(function() {
          document.getElementById('lightbox-22556401244951').click();
        });
      }
        jQuery.cookie('shownDialog', 'true', {expires: 7});
  });

});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top