Posted By

scriptmakingcom on 03/16/08


Tagged

url strip name domain uri


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

paullorentzen
jamesming
apawson
wirenaught


Strip domain from url (without http://)


 / Published in: JavaScript
 

URL: http://www.devguy.com/bb/viewtopic.php?p=1899

  1. function getDomain(str)
  2. {
  3. if (str == null || str.length == 0)
  4. return "";
  5.  
  6. str = cleanURL(str).toLowerCase();
  7.  
  8. var i = str.indexOf("/");
  9. if (i > -1)
  10. str = str.substring(0, i);
  11.  
  12. var parts = str.split('.');
  13.  
  14. var len = parts.length;
  15.  
  16. if (len < 3)
  17. return str;
  18.  
  19. var lastPart = parts[len-1];
  20. var secondPart;
  21.  
  22. secondPart = parts[len-2];
  23.  
  24. var two = 2;
  25.  
  26. if (lastPart == "uk" && secondPart == "co")
  27. ++two;
  28.  
  29. if (len >= 0)
  30. return parts.splice(len-two, two).join('.');
  31.  
  32. return "";
  33. }

Report this snippet  

You need to login to post a comment.