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

169
Visualizações
Replace Empty URL Space with %20 for HTML Link

I have a function that I thought I had working to replace a URL with an HTML link when someone submits something on a form of ours. If the users enters a URL with a space, for example:

company.sharepoint.com/sites/testsite/shared documents/forms/allitems.aspx

The function cuts off anything after the space.

Below is my code:

ReplaceURLwithHTMLLinks: function(text) {
 if (text !=null && text.length > 0) {
  var exp = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|}{\[\]\(\)"'])/i;

  if (text.indexOf("-") > -1) {
   
   var linkText;

   if (text.indexOf("company.sharepoint.com") > -1
    linkText = text.substring(0, text.indexOf('-') - 1) + " - SharePoint";
   else
    linkText = text.substring(0, text.indexOf('-') - 1);

   var newLink = text.replace(exp, "<a target='_blank' rel='noopener noreferrer' href='$1'>" + linkText + "</a>";

   return newLink.substring(newLink.indexOf("<a"));
   }
 }

 else {
  return test;
  }
}

I am trying to find out how to replace any blank spaces with a %20 to still allow the HTML Link to load properly

Thanks

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

You could try this?

text.replace(/\s/g, "%20");

it replaces all the empty spaces with %20

about 4 years ago · Santiago Gelvez 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