- Home /
 
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.
No one is obliged to help you even if you try hard with capital letters.
@Fictional: I think you have no idea what a domain name is, right?
www.unity3d.com is the domain name. It's not an url.
  http://www.unity3d.com/SomeResource
 |      |               |            |
 |   1  |       2       |      3     |
 
                  In this case the url only has 3 parts:
The scheme or protocol
The domain name or Host
a path
If you just want to have "unity3d", that's just the second-level-domain-name part without the top-level and third-level parts.
  www.unity3d.com
 |   |       |   |
 | 3 |   2   | 1 |
 
                  Is the top-level domain name
Is the second-level domain name
Is the third-level domain name
All 3 together form a complete domain name.
Answer by Bunny83 · Oct 28, 2014 at 06:56 PM
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[i]);
 }
 
               In UnityScript it looks the same, but since UnityScript doesn't have char-literals you have to use:
 var parts = uri.Host.Split("."[0]);
 
              Answer by Itaros · Oct 28, 2014 at 06:36 PM
Use string operations: http://msdn.microsoft.com/en-us/library/system.string%28v=vs.110%29.aspx
or regex :)
Your answer
 
             Follow this Question
Related Questions
Read Current URL 1 Answer
Locking levels on a level map? 1 Answer
check if each element in string is true simultaneously? 1 Answer
Do Objects Collide? 0 Answers