Question

So I'm trying to put a banner below a Unity app which is hosted on Facebook. I have the following code for injecting html elements above the app in the facebook canvas, taken from https://developers.facebook.com/docs/unity/reference/current/CUI/

string injection =
  "var headerElement = document.createElement('div');" +
  "headerElement.textContent = ('Check out our other great games: ...');" +
  "var body = document.getElementsByTagName('body')[0];" +
  "var insertionPoint = body.children[0]; " +
  "body.insertBefore(headerElement, insertionPoint);";
Application.ExternalEval(injection);

How would I go about displaying these elements BELOW the facebook app?

Was it helpful?

Solution 2

Just replace the line

"var insertionPoint = body.children[0]; "

for

"var insertionPoint = body.lastChild;"

I post tricks and tutorials on my blog, check it out also for facebook sdk tutorials!

blog.bigfootgaming.net

OTHER TIPS

Here's my final solution, taking different browsers into account

string injection = "if(navigator.userAgent.indexOf(\"Firefox\") >= 0){;" +

            "var headerElement = document.createElement('div');" +
            "headerElement.innerHTML = '<img src=\"URLTOSOURCE" style=\"width: 100%; text-align: center\" />';" +
            "var body = document.getElementsByTagName('body')[0];" +
            "var insertionPoint = body.lastChild;" +
            "body.insertBefore(headerElement, insertionPoint);" +

            "}else{;" +

            "var headerElement = document.createElement('div');" +
            "headerElement.innerHTML = '<img src=\"URLTOSOURCE" />';" +
            "var body = document.getElementsByTagName('body')[0];" +
            "var insertionPoint = body.children[0]; " +
            "var unityPlayer = document.getElementById('unityPlayerEmbed');" + 
            "unityPlayer.parentNode.insertBefore(headerElement, unityPlayer.nextSibling);" +
            "var embedTag = unityPlayer.getElementsByTagName('embed');" + 
            "embedTag[0].setAttribute('style','display:block;width:1200px;height:600px');" +

            "};";

    Application.ExternalEval(injection);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top