URI parsing

by 4 contributors:

When dealing with the facilities of nsIURI, the task of parsing a URI can still require additional work.

It's advised that you use the nsIEffectiveTLDService.

Grabbing the main domain using the EffectiveTLDService

Even using the ETLDService, you're unable to get just the base domain sans TLD. So, here's some sample code to determine the base domain without any suffixes:

var eTLDService = Components.classes["@mozilla.org/network/effective-tld-service;1"].
                  getService(Components.interfaces.nsIEffectiveTLDService);
var suffix = eTLDService.getPublicSuffix(aURI);
var basedomain = eTLDService.getBaseDomain(aURI); // this includes the TLD
basedomain = basedomain.substr(0, (basedomain.length - suffix.length - 1)); // - 1 to remove the period before the tld

 

Document Tags and Contributors

Contributors to this page: wbamberg, Brettz9, GG, Sheppy
Last updated by: wbamberg,
Hide Sidebar