Search Unity

call external javascript method from the web player and back again

Discussion in 'Editor & General Support' started by badescuga9, Aug 7, 2014.

  1. badescuga9

    badescuga9

    Joined:
    Dec 11, 2012
    Posts:
    37
    Hi! we're developing a game in unity3d and trying out deploying on facebook. Because we are trying to monitor campaigns we need the actual URL from the place (not the Application.absoluteURL that returns the host of the .unity3d file).. So we need to call some javascript from the webplayer. We achieve this succesfully using:

    Application.ExternalEval(string)

    but are having trouble call a method in response from javascript back to the webplayer.. so here is out code:

    stringfbGetRealAbsoluteUrl = @"
    document.getElementById(""unityPlayerEmbed"").SendMessage(""MetricsManager"",""SetFacebookActualUrl"",window.location);
    ";
    Application.ExternalEval(stringfbGetRealAbsoluteUrl);


    where "unityPlayerEmbed" is the id of the unity3d div:

    <div id="unityPlayerEmbed"><embed src="https://www.site.com/unity/staging.unity3d" type="application/vnd.unity" width="1337" height="912" firstframecallback="UnityObject2.instances[0].firstFrameCallback();" logoimage="https://www.site.com/images/loading.png" progressbarimage="https://www.site.com/images/loading_bar.png" progressframeimage="https://www.site.com/images/loading_bar_frame.png" disablecontextmenu="true" backgroundcolor="000000" bordercolor="000" textcolor="ccc" style="display: block; width: 820px; height: 690px;"></div>

    this div is the standard code generated by Facebook for Unity integration.

    So, the javascript gets called (checked it using different console outputs) but the SendMessage doesn't reply back. What am i doing wrong?


    Here are a couple of links to documentation:

    http://docs.unity3d.com/Manual/UnityWebPlayerandbrowsercommunication.html
    http://docs.unity3d.com/Manual/WorkingwithUnityObject.html