Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by uv · Mar 10, 2014 at 08:56 AM · javascriptfacebookhtmlexternalexternal-tools

Facebook external eval ?

Hi, I have a unity web game which uses a external .js plugin which I source in the unity html ...But facebook uses the .unity3d file directly and I am not able to source in the .js plugin or the html file...on the facebook developer page they say...

Injecting your own HTML/JS

You may wish to add HTML or Javascript code around the Unity object. You can do this using Unity Web Player's DOM mutation/JS execution functions, such as Application.ExternalEval().

Example

Add a div element to the top of the iframe containing the game, which might contain a header for cross-promotion or related uses.

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

..I dont know how to or where to put in the code to get it work...here is what i put in the unity html file to reference the .js plugin...

Can you tell me how we can achieve this...reference the html and js plugin ? Please Help !

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image uv · Mar 10, 2014 at 08:59 AM 0
Share

type="text/javascript" src="JAVAPLUGIN.js">

(the ( script>)start not getting typed..)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Vizionz · Aug 19, 2014 at 07:21 PM

Assuming you are using C# - Try creating the Javascript code in this format:

 string injection =    "var yourScript = document.createElement(\"script\");" +
                 "yourScript.type = \"text/javascript\";" +
                 "yourScript.src = \"//URLtoSource\"" +
                 "document.getElementsByTagName(\"body\")[0].appendChild(yourScript);";
 
 Application.ExternalEval(injection);

For HTML this can be done the same way, but you need to select which tag add to in "var yourScript = document.createElement(\"script_-or-div-or-_header\");" as well as the .type and where you append the code within the HTML body.

To execute this code, add this snippet to the appDelegate. Application.ExternalEval() will inject the code when the unity player loads and when the script is called. This can be done at the beginning (in appDelegate) or at a later time when it is needed. For my purposes, it was done at the very beginning because we have code that is dependent on this injection being completed before hand.

If the source code being injected is from an external source, I recommend conducting the injection as early as possible, because you will not know when the source injection has been completed. (Technically you can know when the source completes, but will take more setup by using callbacks from the webplayer. Research Unity Web Player and browser communication.)

EDIT: Additional information.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

configure/inject backgorund in facebook canvas 0 Answers

Reading and Storing External Data into Memory (From Text) 1 Answer

Open a local html file in the Android's default browser 1 Answer

Facebook instant games with Unity without tiny mode 0 Answers

Unable to connect to Update Server 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges