Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 Respuestas
Responde la pregunta

0

You could try this?

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

it replaces all the empty spaces with %20

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda