0

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?

Xtian
  • 3,535
  • 11
  • 55
  • 91

2 Answers2

3

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});
    });
scrappedcola
  • 10,423
  • 1
  • 32
  • 43
  • 1
    No, the `ready` event happens when the document is loaded, and the `load` event happens when also all content in the document is loaded. The `ready` event normally happens before the `load` event, except sometimes in IE as jQuery has to emulate it. Running the code immediately will make it run before the `load` event. – Guffa Sep 13 '12 at 19:22
0

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

});
Guffa
  • 687,336
  • 108
  • 737
  • 1,005