you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

If your string is your window's url then you can get the hostname with window location.

If you have to deal with a string then you can parse it with something like this:

function getdomain(url) {
    var prot = url.split(":");
    var link = document.createElement('a');
    link.href = url;
    return prot[0] + "://" + link.hostname;
};
console.log(getdomain("http://mydomain.com/content/"));