Results 1 to 3 of 3

Thread: add time delay in on javascript popup

  1. #1
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default add time delay in on javascript popup

    Hi

    I have a javascript popup that displays once per session, is it possible to add a time delay in as well so it pops up after 3 seconds as well as once per session, below is the coding I have so far

    Code:
    <script type="text/javascript">
    $(document).ready(function() {	
    
    	if (once_per_session==0)
    		loadpopunder()
    	else
    	{
    	if (get_cookie('popunder')==''){
    		loadpopunder()
    		document.cookie="popunder=yes"
    	}
    	}
    
    	
    
    });
    </script>
    
    <script type="text/javascript">
    
    //Pop-under window II- By JavaScript Kit
    //Credit notice must stay intact for use
    //Visit http://javascriptkit.com for this script
    
    //Pop-under only once per browser session? (0=no, 1=yes)
    //Specifying 0 will cause popunder to load every time page is loaded
    var once_per_session=1
    
    ///No editing beyond here required/////
    
    function get_cookie(Name) {
      var search = Name + "="
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
          offset += search.length
          // set index of beginning of value
          end = document.cookie.indexOf(";", offset);
          // set index of end of cookie value
          if (end == -1)
             end = document.cookie.length;
          returnvalue=unescape(document.cookie.substring(offset, end))
          }
       }
      return returnvalue;
    }
    
    function loadornot(){
    if (get_cookie('popunder')==''){
    loadpopunder()
    document.cookie="popunder=yes"
    }
    }
    function loadpopunder(){
    
    		var id = '#dialog';
    	
    		//Get the screen height and width
    		var maskHeight = $(document).height();
    		var maskWidth = $(window).width();
    	
    		//Set heigth and width to mask to fill up the whole screen
    		$('#mask').css({'width':maskWidth,'height':maskHeight});
    		
    		//transition effect		
    		$('#mask').fadeIn(1000);	
    		$('#mask').fadeTo("slow",0.8);	
    	
    		//Get the window height and width
    		var winH = $(window).height();
    		var winW = $(window).width();
                  
    		//Set the popup window to center
    		$(id).css('top',  winH/2-$(id).height()/2);
    		$(id).css('left', winW/2-$(id).width()/2);
    	
    		//transition effect
    		$(id).fadeIn(2000); 	
    	
    	//if close button is clicked
    	$('.window .close').click(function (e) {
    		//Cancel the link behavior
    		e.preventDefault();
    		
    		$('#mask').hide();
    		$('.window').hide();
    	});		
    	
    	//if mask is clicked
    	$('#mask').click(function () {
    		$(this).hide();
    		$('.window').hide();
    	});	
    }
    
    </script>
    Thank you in advance

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    What do you mean? Every three seconds? After three seconds regardless of whether or not it has been seen this session? On load and then once again after 3 seconds if it hasn't been seen this session?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by jscheuer1 View Post
    What do you mean? Every three seconds? After three seconds regardless of whether or not it has been seen this session? On load and then once again after 3 seconds if it hasn't been seen this session?
    sorry what I meant was have the popup show after 3 seconds of the page load and then not to show again so will show once

    I have managed to get it sorted now with the following code

    Code:
    <script type="text/javascript">
    $(document).ready(function() {	
    
    	if (once_per_session==0)
    		var to_pop = setTimeout("loadpopunder()", 3000);		
    	else
    	{
    	if (get_cookie('popunder')==''){
    		var to_pop = setTimeout("loadpopunder()", 3000);
    		document.cookie="popunder=yes"
    	}
    	}
    
    	
    
    });
    </script>

  4. The Following User Says Thank You to ianhaney For This Useful Post:

    italiano743 (10-28-2016)

Similar Threads

  1. Delay the auto fade-in slideshow for a given time
    By Cooper in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 09-19-2011, 10:43 PM
  2. Time Delay for Loading Graphics
    By Jim Weinberg in forum JavaScript
    Replies: 4
    Last Post: 04-17-2011, 06:05 PM
  3. Time Delay for Imagetooltip
    By Mng026 in forum Dynamic Drive scripts help
    Replies: 8
    Last Post: 05-08-2008, 12:31 AM
  4. Neon Lights - delay time?
    By mrafled in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 04-23-2007, 11:14 PM
  5. Time delay before script runs
    By hecon in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 09-10-2005, 09:41 PM

Bookmarks

Posting Permissions

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