View Full Version : Loading ads dynamically

05-19-2012, 09:37 PM

I'm trying to load the ads on my site dynamically and have ran into an issue and was hoping for some help.

First - I can get the ads to load using vanilla javascript with the code below.

var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", OAS_url + "adstream_sx.ads/" +sitePage + "/" + uniqid() + "@" + pos);
var ifrmId = "ifrm_" + uniqid();
ifrm.setAttribute("id", ifrmId);
ifrm.setAttribute("marginwidth", 0);
ifrm.setAttribute("marginheight", 0);
ifrm.setAttribute("frameborder", 0);
ifrm.setAttribute("scrolling", 0);
ifrm.setAttribute("height", container.scrollHeight + (container.offsetHeight - container.clientHeight));
ifrm.setAttribute("width", container.scrollWidth + (container.offsetWidth - container.clientWidth));


But since the site is using jquery I wanted to develop it out that way. So I have the following code,

iRandom = oas.uniqid();
sAdURL = opt.url + 'adstream_mjx.ads/' + opt.sitepage + '/1' + iRandom + '@' + sPos + '?' + opt.query;

$('<iframe />', {
src: sAdURL,
id: sPos

I figured the reason this isn't working is the difference between appendChild and appendTo and the fact that things are jquery objects.

So again the top code block renders the ads and the lower code block just shows the javascript code from the ad provider. Any help to get this to work in jquery would be grateful.


05-20-2012, 06:45 AM
yeah i get that its an abstraction of js. After looking into the issue more its because the returned code from the ad service is using document.write.

I can't change the output form them, but I have been trying to find a way to get the ads to load on dom ready. I was thing of overwriting the document.write function but I'm not sure on the correct way to do this.