Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Location
    Toronto, ON
    Posts
    102
    Thanks
    12
    Thanked 1 Time in 1 Post

    jQuery delay the call of a function

    Hi guys,

    Still trying to wrap my head around this jquery stuff. Right now I have a form that pops up 15 seconds after page load asking a user to subscribe id="popupcontainer". It will only popups up if it can't find the 'popup' cookie, hence the if satement:


    Code:
    if ( !getCookie( 'popup' ) ) {
      $(function() {
        $("#popupcontainer").delay(15000).fadeIn();
        $('#black').delay(15000).fadeIn();
      });
    }
    I also have some jquery popups that handle the login/register features. My issue is if someone clicks login within the first 15s of page load the login popup appears id="login" and then the subscribe popup will appear over top of it - not very good usability.

    What I want to do is wait 15s, see if the login is visible and if not, display the subscribe box. if the login is visible, wait 15s and try again:

    Code:
    //wait 15s
    if($("#login").css('display')=="none"){
      $("popupcontainer").fadeIn();
    }else{
     //wait another 15s and try again
    }
    Anybody have any idea how I can go about this?? Any help is much appreciated!!!!
    Last edited by inchecksolution; 01-24-2012 at 06:28 PM.

  • #2
    Regular Coder
    Join Date
    Jul 2011
    Location
    Toronto, ON
    Posts
    102
    Thanks
    12
    Thanked 1 Time in 1 Post
    anybody have any ideas????

  • #3
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Code:
    // check after 15 secs
    window.setTimeout(checklogin, 15000);
    
    function checklogin() {
       // is login box hidden?
       if($('#login').is(':hidden')) {
          // it is hidden, so display subscribe box (if there is no cookie)
          if ( !getCookie( 'popup' ) ) {
             $("#popupcontainer").delay(15000).fadeIn();
             $('#black').delay(15000).fadeIn();
          }      
       } else {
          // it is visible, wait another 15 secs
          window.setTimeout(checklogin, 15000);
       }
    }

  • #4
    Regular Coder
    Join Date
    Jul 2011
    Location
    Toronto, ON
    Posts
    102
    Thanks
    12
    Thanked 1 Time in 1 Post
    Thanks devnull. What you suggested didn't work, but lead me in the right direction. This is what I ended up with:

    Code:
    window.onload = function(delay){
    	setTimeout(checkpopup, 15000);
    };
    function checkpopup(){
    <!-- ACTIVATE POPUP -->
     if ( !getCookie( 'popup' ) ) {
    	 if($('#black').css('display')=='none'){
    		$(function() {
    		  $("#popupcontainer").fadeIn();
    		   $('#black').fadeIn();
    		});
    	 }
    	 else{
    		 setTimeout(checkpopup,15000);
    	 }
     }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •