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

95
Visualizações
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 Respostas
Responde à pergunta

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 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