简体   繁体   English

Facebook和Unity3D JS注入困难

[英]Facebook and Unity3D JS injection difficulties

I'd like to display some HTML elements under my game on Facebook. 我想在Facebook上的游戏下显示一些HTML元素。 Specifically, an image with a link to a website, but that's not the point of the question. 具体地说,是带有网站链接的图像,但这不是问题的重点。

I understand what is required, and have successfully used the Application.ExternalEval() method, and the sample JS string provided by Facebook, to add some HTML text on top of the game itself. 我了解要求什么,并成功使用了Application.ExternalEval()方法和Facebook提供的示例JS字符串在游戏本身之上添加了一些HTML文本。

I am following the information found on this page . 我正在关注此页面上的信息。

I have attempted the following permutations: 我尝试了以下排列:

"var insertionPoint = body.children[0]; " + "body.insertBefore(headerElement, insertionPoint);";

"var insertionPoint = body.children[0]; " + "body.insertBefore(headerElement, insertionPoint.nextSibling);";

"var insertionPoint = body.children[1]; " + "body.insertBefore(headerElement, insertionPoint);";

After a couple of hours of frustrating trial and error, I have been unable to produce working JS injection code to display HTML immediately below the game itself on the canvas. 经过几个小时的反复试验,我无法产生有效的JS注入代码来在游戏本身的下方画布上立即显示HTML。 Can someone help? 有人可以帮忙吗?

This should do the trick! 这应该可以解决问题!

"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

I've been trying to do the same frustrating thing for a minute, here's what I've arrived at, had to use different techniques for different browsers. 我一直在尝试做同样令人沮丧的事情一分钟,这就是我所要达到的目标,必须对不同的浏览器使用不同的技术。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM