utroda17 0 Newbie Poster

Hello,

I'm trying to load ad on my site dynamically and I can't seem to get it to work... Well I can get it to work using vanilla javascript, but not with jquery & I would like to use jquery if possible.

thisAd = $(oAds[i]);
sPos = thisAd.attr('data-adname');

// if theres a key
if(adKeys[sPos]){
    if(thisAd.children().length >= 1){
        thisAd.children().remove();
    }

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


    $('<iframe />', {
        src: sAdURL,
        id:   'myFrame'
    }).appendTo(thisAd);

}else{
    console.log("Error");
}

The above code doesn't load the ad, it just displays the code the ad service uses wrapped in <pre> tags.

 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));


    container.appendChild(ifrm);

The code above loads the ads just fine. I figured the issues was appendChild vs appendTo?

Any help to get this working would be grateful.