所以我试图在Facebook上托管的Unity应用程序下面放一个横幅。我有以下代码用于在Facebook画布上的应用程序上方注入html元素,取自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);
我如何在Facebook应用程序下显示这些元素?
答案 0 :(得分:2)
这是我的最终解决方案,考虑了不同的浏览器
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);
答案 1 :(得分:1)
只需替换
行"var insertionPoint = body.children[0]; "
的
"var insertionPoint = body.lastChild;"
我在博客上发布技巧和教程,也可以查看facebook sdk教程!
blog.bigfootgaming.net