Fahim Akhter
Fahim Akhter

Reputation: 1625

How to refresh div in javascript, which has another script as body?

I was using an advertising service (banner) which had a simple refresh timer in it. Where I could specify after what time the advert should be reloaded (or a new one should be served)

I've switched my banner provider and the new one does not have that built in option.

I've tried refreshing the div normally but that doesn't work since the content seems to remain the same.

Any ideas on a javascript code which can refresh a banner ad?

<script langauge="javascript">  
window.setInterval("refreshDiv()", 60000);  
function refreshDiv(){  
    document.getElementById("advert_div").innerHTML;
}
</script>

and here is the advertisers div

<div id="advert_div">
        <script type="text/javascript">
            //<![CDATA[
                LSM_Slot({
                    adkey: '645451',
                    ad_size: '300x250',
                    slot: 'slot656464'
                });
            //]]>
        </script>
    </div>

Upvotes: 0

Views: 16141

Answers (1)

Mirko Cianfarani
Mirko Cianfarani

Reputation: 2103

I say my idea or suggest. I had one situation but there was the script with document.write() and this is not that you used. Info: my answer (I was writing before the update's question)

2. idea In your case

  <script language="javascript">  
    window.setInterval("refreshDiv()", 60000);  
    function refreshDiv(){  
        document.getElementById("advert_div").innerHTML;
    }
    </script>

The document.getElementById("advert_div").innerHTML miss = as what?

Example

document.getElementById("advert_div").innerHTML="<p>Welcome</p>"

EDIT:

You can create the element with

document.getElementById("advert_div").innerHTML="";
         var src1 = 'script',
                script1 = document.createElement('SCRIPT');
                script1.type="text/javascript";
           script1.src = src1;
           document.getElementById("advert_div").appendChild(script1);

This is a banal example but you can create the function in every banner and create the function:

"use strict";
var name = "foo";
var func = new Function(
     "return function " + name + "(){ alert('sweet!')}"
)();

//call it, to test it
func();

Info:

function refreshDiv(){  

            document.getElementById("advert_div").innerHTML="";
            //Calling the function using the if
        }

Now I do not know exactly what you want to do and I writing my ideas. Good luck and if you seek help.

Upvotes: 3

Related Questions