5 Replies Latest reply on Sep 4, 2017 10:14 AM by Joel_Geraci

    Javascript for "Is javascript enabled?"

    Brian3.14 Level 1

      Hi all:

       

      Working with Acrobat X Pro; would like to have a long, locked text field  ("txtWarning") with a default value advising the user to re-open the form with Reader/Acrobat and make sure javascript is enabled for helpful navigation and calculations. (So the default assumption is javascript is either disabled or it's been opened by something other than Reader or Acrobat - aka *******' Preview.)

       

      Seems it should be possible to then, on document open, test to see if javascript is enabled, and if it is, change the value of this.getField("txtWarning").value to something other than the warning --- a helpful hint or something. 

       

      Been reading a lot about OCG layers, etc. for the problem of Preview in MAC or javascript being disabled but can't find anything on just determining if javascript is enabled, which would seem to be the first step.

       

      Thanks!

       

      Brian

        • 1. Re: Javascript for "Is javascript enabled?"
          Joel_Geraci Adobe Community Professional

          You can't use JavaScript to test if JavaScript is enabled when JavaScript isn't available... but you don't need to know if JavaScript is enabled. If your script doesn't run, it's not enabled.

           

          You just set up the document to look the way you want it to if JavaScript isn't available then use JavaScript to change it in a way that demonstrates that it is.

           

          You do want to use layers though (OCGs). Different viewers will render the form field differently but layers will always look right.

           

          That said, you can set a "requirement" on the document via JavaScript during the authoring process that will tell the viewer that the document requires JavaScript to be enabled. This functions regardless of JavaScript being enabled or not. I've never seen it work outside of the Adobe viewers though. See documentation below for addRequirement.

           

          Acrobat DC SDK Documentation

          • 2. Re: Javascript for "Is javascript enabled?"
            Brian3.14 Level 1

            Joel -

             

            Thanks for the response --- AND for not saying you're making it more difficult that it needs to be, lol.

             

            Totally see your point.  Just run the code on PageOpen.  If it fires, there's Javascript.

             

            Layers are completely new to me but I began experimenting with them last night. Will try more later on and respond back.  Thanks much; more to follow!

             

            Brian

            • 3. Re: Javascript for "Is javascript enabled?"
              gkaiseril MVP & Adobe Community Professional

              One could also run the JavaScript as a documents level script so it fires whenever the document is opened. This takes care of the issue if the PDF is opened to a page other than the first page.

              • 4. Re: Javascript for "Is javascript enabled?"
                Brian3.14 Level 1

                HI all:

                 

                Sorry delay; death in the family. =(  Tell the people you love that you love them.

                 

                Thanks again to Joel_Geraci and gkaiseril for the comments.  Those layers are pretty useful!

                 

                Since form fields render "on top" of the layers, and since Preview on Mac has issues with displaying form fields in their exact location, I was also going to set all my fields to hidden and then run a documents level script (thx gkaiseril!) to show all the hidden fields on open.

                 

                But there's a problem on DOC CLOSE.  If the end user does NOT save changes before closing the file, then a script to re-set all fields back to hidden (in the close event) won't work, I think.  Any way around this?

                 

                Thanks!

                 

                Brian

                • 5. Re: Javascript for "Is javascript enabled?"
                  Joel_Geraci Adobe Community Professional

                  Preview on the Mac will corrupt all of your JavaScript anyway. Even if you don't save the file, just closing it will rewrite the PDF and break it. What are your form fields for?

                   

                  J-