Get file server domain with Javascript or jQuery

I want to get plain domain without http(s)://www. (e.g. result of script is example.com) from the file link (http://www.example.com/file.exe or https://example.com/folder/file.txt#someValue?params).

How I can do it with js or jquery?

Answers 1

  • This can be done with plain javascript.

    var url = new URL("https://example.com/folder/file.txt#someshit?someothershit");
    var hostname = url.hostname.replace("www.", "");
    console.log(hostname);


Related Articles