简体   繁体   中英

Jquery: Code working in Chrome but not in Firefox

I have a function showBubble() which runs on page load

var showBubble = function() {
                if ($.cookie("bubblepromo")) {
                    if ($.cookie("bubblepromo") == "deleted") {
                        $(".authorization-link .popup").hide();
                    } else {
                        $(".authorization-link .popup").show();
                    }
                } else {
                    $.cookie("bubblepromo", "popup", { path: '/' });
                    $(".authorization-link .popup").show();
                }
                $(".authorization-link .popup #close").click(function () {
                    $.cookie("bubblepromo", "deleted", { path: '/' });
                    $(".authorization-link .popup").hide();
                });
                alert('show bubble');
            }
   
$(window).on('load', function(){
    setTimeout(showBubble, 3000);
});

I have used setTimeout to run the jquery 3 secs after page load. The function showBubble() shows a bubble popup based on value of a cookie bubblepromo

The above code works fine in Chrome but doesn't work in Firefox. I used Firefox debugger and set a breakpoint for this line of code

$(".authorization-link .popup").show();

But for some reason this line of code is not getting executed sometimes. This issue is intermittent.

Replace $(window).on('load') with document.ready function:

$(document).ready(function(){ 
//method goes here
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM