1

Information: I have made a "tabs" type section to display all of my legal forms (https://get.goreact.com/legal/). I have given each individual tab an ID that populates in the URL. For example when I click "Privacy Policy" the URL changes to (https://get.goreact.com/legal/#legal|2).

Problem Trying To Solve: The URL changes depending on what tab/button you click on. But if you try going that the URL directly (or a new tab) it doesn't open the correct tab/display the correct content.

What code do I need to add in order to have the URL "https://get.goreact.com/legal/#legal|1" and "https://get.goreact.com/legal/#legal|2" and so on open the respective tabs? I am new to JS and need some help.

Adam Baird
  • 167
  • 5
  • 1
    Java is to Javascript as Pain is to Painting, or Ham is to Hamster. They are completely different. It is highly recommended that aspiring coders try to learn the name of the language they're attempting to write code in. When you post a question, please tag it appropriately - this lets those with knowledge of the language you need help with to see your question – Harshal Parekh Jun 25 '20 at 17:11
  • Sorry about that. I am a noob about these things. I removed Java. – Adam Baird Jun 25 '20 at 17:24
  • [Something in my web site or project doesn't work. Can I just paste a link to it?](https://meta.stackoverflow.com/questions/254428/something-in-my-web-site-or-project-doesnt-work-can-i-just-paste-a-link-to-it) – Alon Eitan Jun 25 '20 at 17:28
  • @AlonEitan I am new to this website. I thought people would help me trouble shoot here. – Adam Baird Jun 25 '20 at 18:02
  • I checked your HTML source and Customer Terms for example as all of your other tab link's do not have #... part. – ikiK Jun 25 '20 at 18:18
  • use this solution = https://stackoverflow.com/questions/34491182/make-bootstrap-tab-active-on-the-bases-of-url-link – Irshad Khan Jun 25 '20 at 18:57

1 Answers1

1

You can use one short solution by using jQuery. After this, you don't have to add or remove any classes to any element.

$(document).ready(function(){

  if( window.location.hash != "" ) {
      $('a[href="' + window.location.hash + '"]').click()
  }

});

Try this once

Irshad Khan
  • 5,670
  • 2
  • 44
  • 39