![]() ![]() JSFiddle Example (it includes the entire minified library in the jsFiddle, so scroll down!): Var parsed = psl.parse(url) // Parse the domainĭocument.getElementById("output").textContent = parsed.domain To get the name from the current page, you can use location.hostname instead of a static string: var parsed = psl.parse(location.hostname) įinally, if you need to parse a domain name directly out of a full URL string, you can use the following: var url = "" co.uk), to get an accurate result in all cases, we need to parse the hostname using the Public Suffix List, which contains a list of all public domain name suffixes.įirst, include the public suffix list js api in a script tag in your HTML, then in JavaScript to get the hostname you can call: var parsed = psl.parse('.uk') Since some domain names have one suffix (. ![]() This solution doesn't make any assumptions about the URL format, so it should work for any URL. Following is a solution to extract a domain name without any subdomains. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |