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?

有帮助吗?

解决方案

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

其他提示

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

});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top