Display last active tab after page refresh

Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
Marius
Posts: 65

Display last active tab after page refresh

I have a tabs effect on a web page and when the page is refreshed it loses the last active tab and goes back to the first tab.
How to make so after the page refresh to remain active the last opened tab?
Has anyone come across this problem and know how to solve it?

Admin
Hi,
You can use the sessionStorage JavaScript object to store data in the browser session, that can be used after page refresh.
You can add data in browser session using this code:

Code: Select all

sessionStorage.setItem('name', value);
And you can get /use the value associated to "name" with this:

Code: Select all

if(sessionStorage.getItem('name')) {
  var some_var = sessionStorage.getItem('name');
}
- In this page: Creating Tabs Effect with JavaScript is an example with tabs effect that uses this technique to keep active the last opened tab, after page refresh.

Similar Topics