- Home /
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!!!
Answer by Graham-Dunnett · Apr 24, 2013 at 08:36 PM
@Graham Dunnett ♦♦ 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)
Answer by bernardfrancois · Jan 01, 2014 at 09:01 AM
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: http://www.previewlabs.com/reading-url-parmeters-from-web-player-builds
Your answer
![](https://koobas.hobune.stream/wayback/20220613100918im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Application.OpenURL crashes on PC 0 Answers
Android wont load AssetBundle scene - using AssetBundleManager from the tutorial (Unity 5.2.1) 2 Answers
How to read URL parameters from Unity WebGL Build 4 Answers
how i can share my screenshot in base64 data to facebook using Unity ?? 0 Answers
Max String Length in WWW url's? 1 Answer