Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
How to get subdomain from url

I have a url like http://abc.xyz.com. I just want 'http://abc' part, But I am getting 'http://abc.xyz.com'

I tried this:

windw.location.origin

Do I need to write some extra method to get the first part of url or is there something any window method which will do the same?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can split it by . and take the first element

window.location.origin.split('.')[0]

Example:

console.log(window.location.origin);
console.log(window.location.origin.split('.')[0]);

about 4 years ago · Juan Pablo Isaza Relatório

0

"http://abc.xyz.com".split(".")[0]
// or
var url = "http://abc.xyz.com";
url.split(".")[0]

returns "http://abc"

about 4 years ago · Juan Pablo Isaza Relatório

0

It's as simple as that: [subdomain] = 'https://abc.def.xyz'.split('.');

var url = 'https://abc.def.xyz';
[subdomain] = url.split('.');
console.log(subdomain);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda