0

I have a jQuery function that counts the number of images (eg. 3 images) in a gallery.

var imageNumber =  $(".ox-images-gallery img").length;  //value=3

How can I pass the value of imageNumber from the current page to another page using jQuery or Javascript?

I tried with:

Page 1

localStorage.setItem('val',imageNumber)

and

Page 2

localStorage.getItem('val');

but the problem is I must go to page 1 first so that the correct value of imageNumber is displayed on page 2. Any other approaches to do this?

Thanks.

clemens
  • 16,716
  • 11
  • 50
  • 65
Brian Cheong
  • 61
  • 3
  • 12
  • 1
    Possible duplicate of [Passing values from one page to another in JavaScript](https://stackoverflow.com/questions/21475052/passing-values-from-one-page-to-another-in-javascript) – A.D. Nov 23 '17 at 03:46
  • Have you taken a look on passing image number in location query string? https://stackoverflow.com/questions/9870512/how-to-obtaining-the-querystring-from-the-current-url-with-javascript , like PAGE1_URL?imagenum=3 – Vitalii Chmovzh Nov 23 '17 at 03:46
  • I don't think I can pass the value through a url parameter since my page's url will keep on changing based on the action performed. Any idea? – Brian Cheong Nov 23 '17 at 03:50
  • 4
    of course you have to go to where the value is set first to set the value. How else is the value going to be set except in the page that sets the value? – Jaromanda X Nov 23 '17 at 03:50
  • @JaromandaX You got the point here. Thanks. – Brian Cheong Nov 23 '17 at 04:13
  • how about this: https://stackoverflow.com/questions/404891/how-to-pass-values-from-one-page-to-another-in-jquery – Ahtisham Nov 23 '17 at 04:34

1 Answers1

1
//save a value
sessionStorage.setItem("name", "Nicholas");

//retrieve item
var name = sessionStorage.getItem("name");
Protium
  • 213
  • 3
  • 13