1

I am building an ASP.NET MVC application which has a left navigation pane showing categories, and the remaining page uses the context of the selected category to do all actions.

When I navigate to the website with http://website/Home/Index?category=1&hideCategories=true i want to hide the navigation pane across all actions till that browser tab is closed. I want to show the navigation pane otherwise.

How can I achieve this while supporting the following scenarios,

  • I want to open two browser tabs side by side with one browser tab always hiding the categories pane while the other browser tab always showing the navigation pane.
sri
  • 1,005
  • 1
  • 12
  • 26

2 Answers2

1

If you want isolation between tabs, Per Browser Tab Storage, then you can use session storage.

Using javascript you can save some value to session storage like this:

sessionStorage.setItem("hideCategories", "true");

Then you can access the value like this:

var x = sessionStorage.getItem("hideCategories");
if(x === "true"){
  //some logic to hide categories
}

You can set this value per browser tab, so you can have one tab where your nav is hidden and one tab where it is not.

Data stored in sessionStorage does not persist after the browser is closed.

Anish Patel
  • 4,332
  • 1
  • 30
  • 45
0

You basically have 2 options:

  1. Use cookie or session (as you mention) to store your data and get it with javascript in all tabs
  2. Use localStorage that implement in all modern browsers to comminicate across tabs in browser.

Like this to set:

localStorage.setItem("item", "hello");

or

localStorage.item = "hello"

And to get:

localStorage.getItem('item');
teo van kot
  • 12,350
  • 10
  • 38
  • 70
  • How can I differentiatge between two tabs. If I want to hideCategories in one browser tab while showing categories pane in other browser tab i cannot use localStorage right. – sri Jul 02 '15 at 06:37