locked
Adding an AD using javascript RRS feed

  • Question

  • I am trying to add an AD on my HTML page from a js file. I am using the following code:

    adDiv= document.createElement('div');

    adDiv.setAttribute("id", "myAd2");

    adDiv.setAttribute("data-win-control", "MicrosoftNSJS.Advertising.AdControl");

    adDiv.setAttribute("data-win-options", "{applicationId: 'd25517cb-12d4-4699-8bdc-52040c712cab', adUnitId: '10043105'}");

    adDiv.setAttribute("style", "width: 150px; height: 120px; border:solid 2px #000");

    document.getElementById("xyz").appendChild(adDiv);

    where div id="xyz" exists.

    Yet, the AD div appears to be blank. Its just the black border that is visible.

    The AD looks and works fine when directly placed in the HTML file:

    <div id="myAd" style="width: 250px; height: 250px; z-index: 1" 
         data-win-control="MicrosoftNSJS.Advertising.AdControl" 
         data-win-options="{applicationId: 'd25517cb-12d4-4699-8bdc-52040c712cab', adUnitId: '10043105'}">
    </div>

    Can't ADs be added from a js file? This seems weird.


    • Edited by Kedar9 Wednesday, March 20, 2013 3:05 AM
    Wednesday, March 20, 2013 3:04 AM

Answers

  • I know Jeff pointed you to Ad forums, just like to point out two things (one of which is relevant for these forums at least):

    1) When you pragmatically inject HTML onto a page, with a "data-win-control" it will not doing what you expect until you run WinJS.UI.processAll() (more: http://msdn.microsoft.com/en-us/library/windows/apps/hh440975.aspx) to process the bindings.

    2) If you are going to use JS to put your advert, it might be better to use the API to insert the code instead using 
    MicrosoftNSJS.Advertising.AdControl (more here: http://msdn.microsoft.com/en-us/library/advertising-windows-sdk-api-reference-adcontrol-constructor(v=msads.10).aspx)

    Friday, March 22, 2013 7:43 AM

All replies

  • Wednesday, March 20, 2013 6:08 PM
    Moderator
  • I know Jeff pointed you to Ad forums, just like to point out two things (one of which is relevant for these forums at least):

    1) When you pragmatically inject HTML onto a page, with a "data-win-control" it will not doing what you expect until you run WinJS.UI.processAll() (more: http://msdn.microsoft.com/en-us/library/windows/apps/hh440975.aspx) to process the bindings.

    2) If you are going to use JS to put your advert, it might be better to use the API to insert the code instead using 
    MicrosoftNSJS.Advertising.AdControl (more here: http://msdn.microsoft.com/en-us/library/advertising-windows-sdk-api-reference-adcontrol-constructor(v=msads.10).aspx)

    Friday, March 22, 2013 7:43 AM