Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!