[英]Unity HTML banner within Facebook's canvas
So I'm trying to put a banner below a Unity app which is hosted on Facebook. 所以我试图在Facebook上托管的Unity应用程序下面放一个横幅。 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/
我有以下代码用于在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);
How would I go about displaying these elements BELOW the facebook app? 我如何在Facebook应用程序下显示这些元素?
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);
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! 我在我的博客上发布技巧和教程,也可以查看facebook sdk教程!
blog.bigfootgaming.net blog.bigfootgaming.net
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.