3 Replies Latest reply on Mar 3, 2014 12:45 AM by illustrate_this

    Incrementing a page number?




      I need to be able to click on my previous and next buttons to navigate between different html pages. These pages will have the naming convention 'Page 1.html'...'Page 2.html'. I want to be able to know what page I am on and then the next/previous button will increment the current page by 1.


      So for example in Page 1.html:


      My stage code


      //create variable which holds current page number

      sym.setVariable("page", 1);



      Next Button OnClick Code


      //Get page variable

      var page = sym.getVariable("page");


      //Open next page and increment by 1

      window.open("Layout " + (page + 1) + ".html", "_self"); *This is the peice of code Im trying to get working!



      Can anyone help me on how to add a variable number into the URL?


      Thanks for any help!

        • 1. Re: Incrementing a page number?
          SimonDBench Level 1

          There a few ways you can do it.  Evaluating the location or via query string  would be 2 ways but I think you would be best to store it in the hash as it's simpler to change to a number.




          When page loads use this to set your variable.  Note if the hash is not set you will need to set it at this point. 




          Then when you navigate make the hash part of the url


          window.open("Layout " + (page + 1) + ".html#"+(page+1), "_self");


          Hopefully this does the job.



          1 person found this helpful
          • 2. Re: Incrementing a page number?
            illustrate_this Level 1

            Thank you so much I am going to try and implement this ASAP! Hopefully i can get it to work!

            • 3. Re: Incrementing a page number?
              illustrate_this Level 1



              Ive had a chance to try this and it works....i think!


              I have a question, do I have to set the hash for every page or just the first page? Right now i have the following for page 1:




              location.hash = "1";






              var page = sym.getVariable("page");

              window.open("Layout " + (page + 1) + ".html#"+(page+1), "_self");



              Now my plan is to duplicate this page (obviously change the content) and this code should automatically update the page number (or hash)?


              Thanks so much for this help its hugely appreciated!

              1 person found this helpful