Can I Read Domain Name?

Is it possible to know the current DOMAIN name and print as string, when an Unity game is loaded in a browser?

NOT URL(www.unity3d.com), I NEED DOMAIN NAME(unity3d).
I try with Application.absoluteURL but I can’t do it.

Is it possible?
Thanks a lot.

Uhm, the domain name is part of the url. The easiest way is to use the “Uri” class of Mono / .NET. Something like this:

var uri = new System.Uri(Application.absoluteURL);
Debug.Log("The domain name is: " + uri.Host);

If you need to access the top, second, third, … level parts of the domain name independently, Just split them on the “.”

// C#
var uri = new System.Uri(Application.absoluteURL);
var parts = uri.Host.Split('.');
System.Array.Reverse(parts); // reverse the array to make the last element the first
for(var i = 0; i < parts.Length; i++)
{
    Debug.Log("Level "+ i + " domain name:" + parts*);*

}
In UnityScript it looks the same, but since UnityScript doesn’t have char-literals you have to use:
var parts = uri.Host.Split(“.”[0]);

Use string operations: String Class (System) | Microsoft Learn

or regex :slight_smile: