obtain url where webplayer is embedded

I have a unity web player game that runs on server . I need to obtain the url of the web page where the unity web player is embedded

public static string fullUrl;

    void Start() {
        Application.ExternalEval("var unity = unityObject.getObjectById(\"Unity\");unity.SendMessage(\"" + name + "\", \"ReceiveURL\", document.URL);");

    }

    public void ReceiveURL(string url) {
        // this will include the full URL, including url parameters etc.
        fullUrl = url;
    }

But this script returns path where the game is stored and not the current url of the web page

I tried Application.datapath too.

How to obtain this url . From this url i need to get the session id

Thanks for help in advance!!!

2 Answers

2

@Graham Dunnett :diamonds::diamonds: Application.absoluteurl returns the file path where the game is hosted. I want the url of the page where the unity web player game is played (To obtain session id)

You can use ExternalEval to pass anything from browser-side JavaScript to your Unity project:

Application.ExternalEval(“UnityObject2.instances[0].getUnity().SendMessage('” + name + “', ‘SetRequestParameters’, document.location.search);”);

Other than document.location.search (which returns the part of the URL starting at the question mark, you could use document.location.href for the full URL (or anything else you may want to pass which is supported in your browser’s JavaScript).

I wrote a RequestParameters class that does this, parses the URL parameters, and exposes a GetValue(string key) function to conveniently read URL parameters: