I was working on how to find a URL's domain, and thanks to my previous question, I came to this answer:
var domain = (location.host)
var arr=domain.split(".")
extension=arr[arr.length-1]
if(extension=="cnn")
alert("true");
However, I have 2 problems:
- It works fine untill you come across to a site with extension
co.uk
. - Is there a way to count
.
from the start and not from the end?
For example, for the website www.cnn.com
, it'd start counting from the www
, and not from the com
.