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

94
Vistas
Javascript open page with variable to open tab of tabbed section

I was looking for a solution to have a certain tab open when page was viewed by Url Parameter. I have seen a few examples but they do not seem to work. Maybe they are to old to work with current javascript. Here is what I have found:

var tabName = (window.location.href.match(/[?&]tab-name=[^&$]+/i) || '=').split('=')[1];
tabName='profile'; // remove this line on real page
if(tabName.length)
$('#myTabs .nav-link[href="#' + tabName + '"]').tab('show');

The above works fine with the // remove this line on real page - in place. once that is taken out and it relies on the varible. Console window says (window.location.href.match(/[?&]tab-name=[^&$]+/i) || '=').split('=')[1]; is not a correct function.

I have this and it does not seem to work either. It gets the parameter but it still needs stripped to get just the parameter to open the tab.

    $(document).ready(function () {
    const urlSearchParams = new URLSearchParams(window.location.search);
    const params = Object.fromEntries(urlSearchParams.entries());
    var tabName = params;
    if (tabName.length)
        $('#myTabs .nav-link[href="#' + tabName + '"]').tab('show');
    debugger
});

Any help would be appreciated..

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I got this to work by doing it this way..

$(document).ready(function () {
    let params = new URLSearchParams(document.location.search.substring(1));
    let name = params.get("name");
    if (name.length)
        $('#myTabs .nav-link[href="#' + name + '"]').tab('show');
    //debugger
});

URL is myAddress.com/Profile?name=settings Weird, when I used the word tabName this didn't work but name does..

about 4 years ago · Juan Pablo Isaza 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