Results 1 to 2 of 2

Thread: Pop up Caller

  1. #1
    Join Date
    Sep 2016
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Pop up Caller

    I have a script that serves as a caller for pop up ads. I want to develop this sript so it only works 12 hours a day (or we can set the time). Anyone can help?
    Code:
    <script>
      document.addEventListener('DOMContentLoaded', function() {
      	if(typeof getCookie('popup-schedule-chuan') == 'undefined'){
    
      	
      		setCookie('popup-schedule-chuan' , 'true' , 1);
      		setTimeout(function(){
      			document.getElementById("xDialog").style.opacity = "1";
      		} , 5000);
      	}
      });
    
      function setCookie(cname, cvalue, exdays) {
    	    var d = new Date();
    	    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    	    var expires = "expires="+d.toUTCString();
    	    document.cookie = cname + "=" + cvalue + "; " + expires;
    	}
    	function getCookie(name) {
    	  var value = "; " + document.cookie;
    	  var parts = value.split("; " + name + "=");
    	  if (parts.length == 2) return parts.pop().split(";").shift();
    	}
    </script>
    Last edited by Beverleyh; 11-01-2016 at 02:27 PM. Reason: formatting

  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

    Perhaps like so, which would stop this happening from 8am till 8pm local time of the user visiting the page:

    Code:
    <script>
      document.addEventListener('DOMContentLoaded', function() {
      	var limit1 = 8, limit2 = 20, hour = new Date().getHours();
      	if(hour >= limit1 && hour < limit2){return;}
      	if(typeof getCookie('popup-schedule-chuan') == 'undefined'){
    
      	
      		setCookie('popup-schedule-chuan' , 'true' , 1);
      		setTimeout(function(){
      			document.getElementById("xDialog").style.opacity = "1";
      		} , 5000);
      	}
      });
    
      function setCookie(cname, cvalue, exdays) {
    	    var d = new Date();
    	    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    	    var expires = "expires="+d.toUTCString();
    	    document.cookie = cname + "=" + cvalue + "; " + expires;
    	}
    	function getCookie(name) {
    	  var value = "; " + document.cookie;
    	  var parts = value.split("; " + name + "=");
    	  if (parts.length == 2) return parts.pop().split(";").shift();
    	}
    </script>
    NOTE: The hours for the limits are in 24 hour notation. The limit2 value is 20, which is 8pm. Once the hour advances to 20 (8pm) the code will run again. So essentially stops at 8am and resumes at 8pm. Other values may be used for the limit1 and limit2 vars if desired.
    Last edited by jscheuer1; 11-01-2016 at 07:14 PM. Reason: minor code improvement
    - John
    ________________________

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

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    agungbudiono (11-03-2016)

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
  •