Refreshing a script tag (ads)

As a site I work on evolves, we ajax in more and more content.

In one section, we’ve eliminated the traditional page view entirely, just ajaxing in all the new content.

We need to do the same thing for the ads surrounding this content, and we’re running into issues (doc.write, I assume). We haven’t been able to refresh the script tag, or even empty the div and add in a new script.

We’re iframing for the moment, but it is not ideal. Many of our ads are flexible, but the iframes cannot dynamically adjust (all the ads are hosted externally). This is not against our TOS (before someone chimes in about that).

Search engines haven’t been much help here. I’m not hitting the right words, or there just aren’t many examples out there.

I’m pretty sure this is possible, I know I’ve seen some sites do it (but I haven’t been able to find them again for examples).

Does anyone have any suggestions or examples?

Thanks. I was doing something similar, but when using <script> tags inside the .html() (yup, trying with jQuery, too), nothing happened. Do I need to “activate” those script tags?

There’s a new version of the innerHTML() function which is called innerXHTML(), apparently its more efficient and works a lot better then both innerHTML() and jQuery’s .html() function. You can read more about it here

http://www.stevetucker.co.uk/innerxhtml.htm

A simple thing you could do is number all the ads and wrap them in divs for example

<div id="ad_1"></div>
<div id="ad_2"></div>

then through a for loop you could set an interval of say 60 seconds or something then the ads refresh. Here’s something that could help

function refreshAdvertisements(){
    for(var i=0; i<2; i++){
        var newAd = getNewRandomAd();
        $('#ad_'+i).html(newAd);
    }
}

setInterval("refreshAdvertisements()", 60000);

Of course you would have to adjust this to your liking but it should give you a basic idea of how to can change the ads with Ajax