문제

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