1

I have a site with banner ads on it. What I need to do is rotate those ads - ie you stay on the homepage (no reload) and every 10 seconds a new ad (from a set of 3 or 4) is displayed.

What I do is have a Javascript function that puts my ad code in an array and cycles through the arrary every 10 seconds and does this (just showing the one line of code relevent to my question):

document.getElementById(DivID).innerHTML = AdText;

DivID is the name of a in the HTML and AdText is the HTML code to display the ad.

This works fine for ads that are images where the ad call is just basically an <img> tag, or Flash/SWFobject embed

But, some ads are JS code supplied by a third party ad agency, for example:

<script language='javascript1.1' src="http://example.net/adj/b4207992.2;sz=468x60;ord=[timestamp]?"></script>

So, basically I'm saying document.getElementById(DivID).innerHTML = "THE ABOVE JS CODE"

Nothing is displayed and I have FF with Firebug and no errors are being displayed.

My guess is that document.getElementById(DivID).innerHTML is setting that code alright (as I have additional code to call a 1x1 image to track impressions and this is logging an impression), but that it is just not executing, maybe JS needs some event like a page load to start it?

Any ideas or alternatives?

0

1 Answer 1

1

The reason is that the new content is not being interpreted. If you use jQuery, .html() should solve your problem. This link explains it much better: Difference between innerHTML and .html() from jQuery

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, many thanks for that and the link - I just tried the code there and without a doubt jQuery looks like a solution.
Any easy way of doing it without JQuery?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.