Integrating Code

2014-02-24
2014-02-25
  • ed brandmark
    ed brandmark
    2014-02-24

    Hi all,

    I have a question about integrating the Safe Iframe code. I have some sample code working if I have the publisher include a certain amount of code in the page. The problem I am having is related to integrating all the code into an include file (a JS file loaded into the page) so that the pages don't have to update.

    So as I see it there are 3 steps to do.

    a) Include 3 JS files - this isn't a problem

    b) Include the class data that has the URL, the width/height, the DIV etc. This is the text/x-safeframe data

    This causes problems as if included in a JS file I have to either document.write it or create a script element and both seem to have timing issues.

    c) Initiate a new safeframes config via:
    (function() {
    var conf=new $sf.host.Config({
    renderFile:http://cdn.atwola.com/_media/uac/r.html,
    positions: {}

    })();

    The problem I have is timing issues- it seems to work sometimes but others it never initiates. I've tried placing the code in a function that gets called every few hundred milliseconds waiting to see if
    $sf.host exists and if so creating the conf=new $sf.host.Config as above but ofte times it never gets started.

    Any suggestions on how to do this? If needed, I can supply some simple codeing
    That I've tried.

    Thanks
    Ed

     
    Attachments
    • Chris Cole
      Chris Cole
      2014-02-25

      There is a booted flag, but it may be only internally supported. I think what you describe lends itself to the code based initialization method. Have your code call the render method for each placement after load and config. There should be some samples in the tests directory of the source three. Also if you go to the creative test tool at http://safeframes.net you can generate and view sample code for a script based rendering of ads.

       
      Attachments
  • Sean Snider
    Sean Snider
    2014-02-25

    Generally here are the steps that we do at Y!

    1.) Property page has an inline script, which configures the SafeFrame host. This can also be external if need be

    2.) SafeFrame data island placed in page, this may also add some stuff to the config for each position and what not

    3.) A bootstrap script runs, which downloads the actual host implmentation, and then reads the configurations, and then renders everything all in one shot. Said bootstrap script is ideally the last thing in the page or close to it.

    Chris is right that the safeframes.net page should help you see a way to do this.