1

I have an ad script running, which is hardcoded into my HTML. Now I want to refresh that ad tag after 240 seconds. Easy way would be to simply load the ad tag in an iframe, and put a refresh on that, but iframes cannot be used in my case.

Right now the ad tag loads like this:

    <div class="banner_728">
        <script type="text/javascript"><!--
            bb = new Object();
            bb.size = "728x90";
        //--></script>
        <script type="text/javascript" src="//adserver.com/tags/tags.js"></script>
    </div>

How could I re-execute that javascript after a set amount of seconds, whilst leaving that ad-tag hardcoded into my site.

Mr.Boon
  • 2,024
  • 7
  • 35
  • 48

1 Answers1

1

Apparently You'll need to load the Ad Server JS again.

var bb, created=false;
function reRun() { 
    bb = new Object();
    bb.size = "728x90";

    if(created) document.body.removeChild( document.getElementById("id-ads") );

    // try this instead
    var js = document.createElement("script");
    js.type = "text/javascript";
    js.src = "//adserver.com/tags/tags.js";
    js.id = "id-ads";
    document.body.appendChild(js);

    created = true;

}
var TIMEOUT = setTimeout( reRun , 240 * 1000 );
reRun();

You may or may not have security issues loading external js on the fly. Please read this post which is going to be helpful for your needs:

How do you dynamically load a javascript file from different domain?

gugateider
  • 1,983
  • 2
  • 13
  • 17
  • Thank you so much!! I think we are nearly there. I am getting an error though. "Uncaught TypeError: Illegal constructor at reRun". Points to the 6th line in your example. The one starting with "var script". – Mr.Boon Jul 18 '17 at 16:23
  • Sorry, this is using PrototypeJS. Download here: http://prototypejs.org/download/ or if you want plain js I've edited the answer, please test that ... – gugateider Jul 18 '17 at 16:34