0

I have two carousels, each with their own id "sliderId", and then i have an id on all the elements within the carousel, so i know how far they have scrolled, "currentFirstId".

I would like to save the indformation in the url, and I have done that by writing:

window.location.href = currentLocation + "#" + sliderId + "=" + currentFirstId;

that give me the result i whant: www.blabla.com/#sliderId?2296=0#sliderId?2337=0

But how do git it to update currentFirstId when I scroll, because as it is now, it's put's the information after already existing text like this:

www.blabla.com/#sliderId?2296=0#sliderId?2337=1#sliderId?2296=0#sliderId?2337=2#sliderId?2296=1#sliderId?2337=3#sliderId?2296=2#sliderId?2337=4.

So how do i get it to update the already existing text, so the output is:

www.blabla.com/#sliderId?2296=2#sliderId?2337=4 ???

I hope it makes sense.

ssilas777
  • 9,672
  • 4
  • 45
  • 68
Flubssen
  • 65
  • 9

2 Answers2

2

Maybe try:

window.location.href = window.location.hostname + window.location.pathname + '#' + sliderId + '=' + currentFirstId;
jeffjenx
  • 17,041
  • 6
  • 57
  • 99
  • yeah that give me the effect i want, but it is only saving data for one of the carousels, and delete the other information, so it only keeps the information from one of the carousel, and not both... :/ – Flubssen Mar 02 '16 at 15:17
  • You probably should rethink this so as to avoid having multiple question marks in your URL. While it isn't necessarily invalid, it is very confusing since the first question mark begins the parameter listing of the query-string. – jeffjenx Mar 02 '16 at 18:12
0

Look at this Post:

URL without query string

Maybe you want to use window.location.origin and append the "#sliderId?2296=0#sliderId?2337=0" part to that rather that using currentLocation.

Community
  • 1
  • 1
SScotti
  • 2,158
  • 4
  • 23
  • 41