-1

I am tracking user way throught the web dynamicly. Last 5 visited pages are showed as Breadcrumb navigation like this:

DogDatabase >> DogName >> UserName >> KennelName >> DogName >> etc....

Its dynamicly generated path of the visited pages... This script is in PHP and it works very well.

Now i am using SESSIONs to move that array of visited pages to another page. Also tried LocalStorage in JS.

My problem is, if the user has more windows of my web. The array is shared for all instances (windows) of my web for 1 user.

So it looks like this:

w1 - widnow 1

w2 - window 2

w1.DogDatabase >> w1.DogName >> w2.UserName >> w1.KennelName >> w2.DogName

But i want it like this:

w1.DogDatabase >> w1.DogName >> w1.KennelName

w2.UserName >> w2.DogName

My question is: How to move array of visited pages to another page to be specific for each window of my web for 1 user in PHP or JS?

Thank you, Andrew

EDIT - !SOLVED! :

So i have done the breadcrumb navigation :)

i have multidimensional array like this:

array (
[0] : (nameOfPage,pageURL)
[1] : (nameOfPage,pageURL)
etc..
)

I used sessionStorage for get this array to another page. Awesome is, the sessionStorage is unique for each window/tab of the web, so i dont need identify the window/tab. When the window/tab is closed, storage is cleared. Next good feature is when the user click on BACK button, sessionStorage is going back to the hystorical value on that page. When the page is reopend from browser wia closed pannels function, sharedStorage is on current value too. So its amazing.

For saving array into sessionStorage:

sessionStorage.setItem(key, JSON.stringify(myarray));

For reading array from sessionStorage:

var myarray = JSON.parse(sessionStorage.getItem(key));

variable key is name:

var key = 'navigation';
BigOHenry
  • 3
  • 3

2 Answers2

0

sessionStorage would be the best solution, I suggest you to use a session storage management library like this one. that can help you store not only a simple text/number data but a whole array like this.

$.setSession('key','value');
$.setSession('array1',[1,2,3,4,5]);
$.setSession('array2',Array(1,2,3,4,5));

and to get this data you just need to use getSession function

$.getSession('key'); // returns 'value'
$.getSession('array1'); // returns [1,2,3,4,5]
Khalid
  • 4,730
  • 5
  • 27
  • 50
-1

Thank you for your tip Adam. It wasnt exactly solution, but it was right way.

I will use sessionStorage instead of localStorage. SessionStorage is separetd for each window/tab and its cleared when the window/tab is closed.

So i dont need to detect the windows (dont need generate the id of window/tab) and dont need care about clearing the storage. LocalStorage is shared for all windows/tabs and need to be cleared manually (closing browser did not clear the localStorage).

BigOHenry
  • 3
  • 3