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

268
Vistas
change url path using jquery

I have made a website for two different languages each being in two different folders en and bn. I want to switch between the folders on href element click using jquery.

<a class="eng_link " style="" href="#"> English</a> 
<a class=" link_active bangla_link " style="" href="#">বাংলা &nbsp;/ &nbsp;</a>

Say, I am currently on www.example.com/en/content?id=1. While clicking the link for english it will redirect to the url www.example.com/bn/content?id=1 and vice versa. Only the bn part of the url will change to en keeping other parts the same. How can I do this?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

This is how I have done it. In the index page of bn:

<a class="eng_link " style="" href="#" id='a' onClick="en_onClick()"> English</a> 
<a class=" link_active bangla_link " style="" href="index" >বাংলা &nbsp;/ &nbsp; </a>  

JS

    function en_onClick() {
     $(location).attr('href');
     var bn_pathname = window.location.href;
     var en_pathname = bn_pathname.replace("bn/", "en/"); 
     window.location.replace(en_pathname);
 }

In the index page of en:

 <a class=" bangla_link link_in" style="" href="#" onClick="bn_onClick()"> বাংলা</a> 
 <a class=" link_active  eng_link" style="" href="#"> English &nbsp;/ &nbsp; </a> 

JS

    function bn_onClick() {
     $(location).attr('href');
     var bn_pathname = window.location.href;
     var en_pathname = bn_pathname.replace("en/", "bn/"); 
     window.location.replace(en_pathname);
 }
about 4 years ago · Santiago Trujillo Denunciar

0

This is how I would do it:

$(".changeLink").click(function() {
  $(".eng_link").attr("href", $(".eng_link").attr("href").replace("en", "bn"))
});

Here is the JFiddle demo

about 4 years ago · Santiago Trujillo Denunciar

0

use this function to change from any language to any language

in your html:

<a class="eng_link " style="" href="#" onclick="changelang('bn','en')"> English</a> 
<a class=" link_active bangla_link " style="" href="#" onclick="changelang('en','bn')">বাংলা &nbsp;/ &nbsp;</a>

and js:

function changelang(langfrom, langto) {
  var url = window.location.href;
  var langfrom= "/"+langfrom+"/";
  var re = new RegExp(langfrom);
  url = url.replace(re,"/"+langto+"/"); 
  window.location = url;
}
about 4 years ago · Santiago Trujillo 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