Save tab-pane active when updating the page

Asked

Viewed 56 times

0

I have a two-tab structure, and I need to keep the active tab active when updating the page. I thought about making a click function that saves the id of the open tab, but I need to send a request (ajax) from js to Session. You can do it, but I was wondering if there’s a better way to do it.

  • Hello William, have you produced any code regarding this question? Could you post it?

  • Good afternoon Ricardo. Actually I only had the logic in my head, because in my point of view this my solution would be a "gambiarra". So I wanted to see if anyone who’s been through this comes up with a better solution than mine.

  • Well, I believe there are other possible solutions, one of them is a cookie, the problem is that it is transmitted to the server at each request, which is probably not desirable. There are still alternatives like Web SQL, but I think it would be a cannon to kill a fly.

  • 1

    Have you ever tried changing the url via javascript when the guy clicks on the tab? when he gives the Reload, it will be with the url you changed, exemplo: seusite.com.br/#tab-pane2, do something similar in the my website

  • Guys, I implemented my logic here and it worked. Thanks for the collaboration.

1 answer

0

When I need something like this I use this library jquery-cookie

The syntax is very simple:

Create:

$.cookie('name', 'value', { expires: 7, path: '/' });

Read:

$.cookie('name');

Rule out:

$.removeCookie('name');

I hope it helps, hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.