4 Replies Latest reply on Jun 11, 2009 2:54 PM by John.Talbot

    How to change page using JS?

    John.Talbot

      Question in subject. Thanks in advance John.T

        • 1. Re: How to change page using JS?
          Martin Fischer Level 2

          Hi John,

           

          try something like this:

           

          var myPage = app.documents.firstItem().pages.item('5'); // page named '5'
          app.layoutWindows.firstItem().activePage = myPage;

           

          or

           

          var myPage = app.documents.firstItem().pages.item(5); // page item 5  
          app.layoutWindows.firstItem().activePage = myPage;

           

          Martin

          1 person found this helpful
          • 2. Re: How to change page using JS?
            Randomsen

            Hey John,

             

            I've wrote these two to navigate through the pages more cleanly, perhaps they may be of use, although they falter with roman numerals and other non-numerical values for the page name, the frame work is there.

             

             

            -------------------------------------------------------------------------------

            //NEXT PAGE

            if (app.selection.length == 0){
            nextpage()}
            else{app.selection = null; nextpage();};

             

              function nextpage(){
                
                 var myCurPage = app.activeWindow.activePage.name;
                 myCurPage++
                     var myNpage = app.activeDocument.pages.item(myCurPage+"")
                         try {app.activeWindow.activePage = myNpage;
                             myzoom();}
                         catch(myError){app.activeWindow.activePage = app.activeDocument.pages.item(0);
                             myzoom();
                     }
                 }
                 function myzoom(){ 
                
                 app.activeWindow.zoom(ZoomOptions.fitPage);
                  
               }

             

             

            -------------------------------------------------------------------------------

            //PREVIOUS PAGE

            if (app.selection.length == 0){
            previouspage()}
            else{app.selection = null; previouspage();};

             

            function previouspage(){
                var myCurPage = app.activeWindow.activePage.name;myCurPage--
                    var myPpage = app.activeDocument.pages.item(myCurPage+"")
                        try {app.activeWindow.activePage = myPpage;
                            myzoom();}
                        catch(myError){
                            var LP = app.activeDocument.pages.length;LP--
                                app.activeWindow.activePage = app.activeDocument.pages.item(LP)
                                    myzoom();
                            }
                        }
                function myzoom(){ 
                app.activeWindow.zoom(ZoomOptions.fitPage);
                }

             

             

             

            ~mike

            1 person found this helpful
            • 3. Re: How to change page using JS?
              John.Talbot Level 1

              It's working good with not empty pages.

               

              Thanks

              John.Talbot

              • 4. Re: How to change page using JS?
                John.Talbot Level 1

                I've wrote these two to navigate through the pages more cleanly, perhaps they may be of use, although they falter with roman numerals and other non-numerical values for the page name, the frame work is there.

                 

                Your two functions working good for me.

                 

                Thanks

                John.Talbot