0

I'm using 2 popup ads tag in my website, so for not disturbing visitors i like to make delay time between first pop up and second pop up by javascript or jquery.

For example

First tag will we execut or load after 60 seconds after full page load and second popup will be load after 20 minuts

TAG 1 :

<script type="text/javascript">
    var ad_id = 111111;
    var ad_advert = 'int';
    var frequency_cap = 5;
    var frequency_delay = 5;
    var init_delay = 3;
    var popunder = true;
</script>
<script src="https://cdn.popup.pop/js/entry.js"></script> 

TAG 2 :

<script type="text/javascript">
    var ad_id = 22222;
    var ad_advert = 'int';
    var frequency_cap = 5;
    var frequency_delay = 5;
    var init_delay = 3;
    var popunder = true;
</script>
<script src="https://cdn.upup.up/js/entry.js"></script> 

Regards

Updated : Still not working, any solution please

<script type="text/javascript">
    var adfly_id = 17609785;
    var adfly_advert = 'int';
    var frequency_cap = 1000;
    var frequency_delay = 0;
    var init_delay = 0;
    var popunder = true;
</script>
<script type="text/javascript">
function injectJs(url) {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.async = true;
  script.onload = function(){
    // remote script has loaded
  };
  script.src = url;
  document.getElementsByTagName('head')[0].appendChild(script);
}

(function() {
 setTimeout(function(){ injectJs('https://cdn.adf.ly/js/entry.js')}, 1000 * 3); // 3 seconds or
 setTimeout(function(){ injectJs('https://cdn.adf.ly/js/entry.js')}, 1000 * 60 * 20); //20 min
 })()
</script>
  • please check this link https://stackoverflow.com/questions/8578617/inject-a-script-tag-with-remote-src-and-wait-for-it-to-execute – atiq1589 Aug 06 '17 at 07:12
  • i see you updated your code with https://cdn.adf.ly/js/entry.js twice. but in your previous example you use https://cdn.popup.pop/js/entry.js and https://cdn.upup.up/js/entry.js. Please check it. – atiq1589 Aug 07 '17 at 03:54

2 Answers2

1

$(window).on('load',function(){
  setTimeout(function(){ ///excute first popup
    console.log('first Excute!')
  },10000);
})

$(function(){
  setTimeout(function(){ ///excute second popup
    console.log('second Excute!')
  },200000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

try this one.

Neeraj Pathak
  • 759
  • 4
  • 13
  • Thank you for your help because i'm novice this is my ad tag please intergate it into your script ------- -------- – help-me007 Aug 06 '17 at 10:21
  • where's your ( cdn.adf.ly/js/entry.js ) JS – Neeraj Pathak Aug 06 '17 at 10:25
0

you can use settimeout function to load js file using this link inject a script tag with remote src and wait for it to execute.

function injectJs(url) {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.async = true;
  script.onload = function(){
    // remote script has loaded
  };
  script.src = url;
  document.getElementsByTagName('head')[0].appendChild(script);
}

(function() {
 setTimeout(function(){ injectJs('https://cdn.popup.pop/js/entry.js')}, 1000 * 60); // 60 seconds or 1 min
 setTimeout(function(){ injectJs('https://cdn.upup.up/js/entry.js')}, 1000 * 60 * 20); //20 min
 })()
atiq1589
  • 2,227
  • 1
  • 16
  • 24
  • Thank you mr for your reply but the solution in your link not working i have tried many times ! – help-me007 Aug 06 '17 at 09:45
  • can you give your code? then it will be helpful for all to debug. – atiq1589 Aug 06 '17 at 09:49
  • thank you i appreciate your help this is the tag of popup i want that will be executed or loaded after 60 seconds after full page load `code` `code` – help-me007 Aug 06 '17 at 09:58
  • please update your main thread. in mean time please check my solution. hopefully it will work. if not please tell me which types of error you are getting. – atiq1589 Aug 06 '17 at 10:13
  • Sir this is my ad tag please intergat it into your script because i have tried many time but is not working maybe i made error thank you,----------- --------------- – help-me007 Aug 06 '17 at 10:51
  • dear its really difficult for me to solve this issue if you did not give me more information. I already wrote the code that will inject JS files 1 min and 2nd one 20 min. after using my code what types of problem you are facing? – atiq1589 Aug 06 '17 at 11:17
  • the js file injected not executed after time seconds ended – help-me007 Aug 06 '17 at 11:29
  • you mean js file not injected after 1 min? – atiq1589 Aug 06 '17 at 11:30
  • sorry my mistake. I had an error in my code snippet. please take this new snippet and try. – atiq1589 Aug 06 '17 at 11:33
  • Hi, i have updated my first post please check it, i have intergated my ad tag in your script but always not working please take a look if you like – help-me007 Aug 06 '17 at 13:53