-1

I'm trying to refresh the web ads after a few seconds. The refresh code in javascript works very well but the ad code also in javascript does not appear after a refresh.

Ads works well only through iframe that the advertising system has as an option.

The reason why I like javascript ads is that they are responsive.

Advertising code:

<div class="ads">

   var m3_u = (location.protocol=='https:'?'https://myweb.com/ads/www/delivery/ajs.php':'http://myweb.com/ads/www/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid=1");
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
   document.write ("&amp;loc=" + escape(window.location));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   document.write ("'><\/scr"+"ipt>");


</div>

Execution interval code:

setInterval("my_function();",3000);
function my_function(){
    $('.ads').load(location.href + ' .ads');
}
Progman
  • 13,123
  • 4
  • 28
  • 43
Root
  • 1
  • 2
  • It's not clear what you're actually intending to do here, either by reviewing your code or your problem statement/description. The first JavaScript snippet you have here is actually an HTML `div` where your "script" will be interpreted as HTML, not executed as JavaScript code. In the second snippet, you've passed your function name as a string, which probably shouldn't work, as it's [not proper syntax](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval). Finally, why have you tagged [tag:java]? Did you mean [tag:javascript]? They are absolutely not the same. – esqew May 13 '21 at 13:16
  • What is it you're trying to accomplish with the line `$('.ads').load(location.href + ' .ads');`? What do you expect [`$.load()`](https://api.jquery.com/load/) to do in this scenario, specifically? Why are you trying to make an AJAX request to the current location's URL with the string `.ads` tacked on to it? – esqew May 13 '21 at 13:18
  • Thank you for your answer @esqew. Yes tag I had done javascript apparently I clicked wrong. So what I want to do I said above.
    CODE SCRIPT
    was setting the javascript code but after an interval update the code hidde from div does not display anything.
    – Root May 13 '21 at 13:21
  • The second answer, I want to refresh the code because the code contains various ads. So I want them to appear from time to time without any browser updates. As I said above it works very well in iframe but not in javascript code. – Root May 13 '21 at 13:24
  • @esqew I also tested it on ajax but it does not work again it does not show anything. – Root May 13 '21 at 13:30
  • 1
    Why would you opt for this setup...? Why not just put your ad code in a `` block and be done with it? `$.load()`'s documentation specifically states that all scripts are stripped when calling it with a specific selector. I would encourage you to, at the very least, read the documentation of the methods you're using before attempting something so convoluted and counter to generally accepted best practices. – esqew May 13 '21 at 13:30
  • 1
    It's also worth noting that the use of `document.write()` in new code is widely considered to be [poor practice](https://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice). – esqew May 13 '21 at 13:31
  • Thank you very much for your reply! I will test $ .load () – Root May 13 '21 at 13:31

0 Answers0