5 Replies Latest reply on Dec 23, 2009 8:52 AM by Raghu Nagireddy

    Conditional Logic Detecting Viewing Source of PDF

    hartmantroy

      I have a piece of Javascript that I'd like to only run when the user is viewing it in a browser window and NOT run when they are viewing it in Acrobat Reader. What is the conditional logic I need to place around my Javascript?

        • 1. Re: Conditional Logic Detecting Viewing Source of PDF
          Raghu Nagireddy Level 3

          We can know where the pdf opened (in browser/stand alone), by using event.target.external value.

           

          Please check the sample pdf open alone and from browser can see the difference.

          In sample odf placed the code on click event of the button.

           

           

          Raghu.

          • 2. Re: Conditional Logic Detecting Viewing Source of PDF
            hartmantroy Level 1

            While you example works (thanks), unfortunately it isn't working for my particular application. So, please let me elaborate a little more...

             

            I have a form where 3 fields get pre-populated using variables from the URL querystring. I have an initialize event on each of the 3 fields that parses the querystring and places the values in the fields. If I open this PDF in a browser from the proper link, it works just fine. If I open it in Reader, it displays errors because it is needing the URL querystring. So, I was hoping to get rid of the errors by placing this conditional logic around that script. However, if I place your conditional logic around the Javascript that does this, it never runs regardless where it is opened.

             

            As a side note, when the 3 fields are pre-populated fro mthe querystring and the user saves the PDF form to their local hard drive and then opens it in Reader, the field values are gone. Any thoughts there also?

            • 4. Re: Conditional Logic Detecting Viewing Source of PDF
              hartmantroy Level 1

              Here is a stripped-down version of the form with all of the identifiable information removed. It does stil

              l have the 3 form fields I'm trying to pre-populate though.

              • 5. Re: Conditional Logic Detecting Viewing Source of PDF
                Raghu Nagireddy Level 3

                If access url from pdf it always show security warning regarding url to allow/ block. here ur getting couple of times bcz same code replicated in all three fields. can be make in to one event and place on page initialize it self.(on field one the closing brace } is missing for top if (event.target.external){ statement)

                 

                To work offline(not in browser) you have to pass the URL querystring into pdf and get the values. in this sample posted here unable to find URL with values or any variable declared inside to get url. now it is giving always the path of the pdf where we saved. In the browser it will work bcz it has access to the url and its values what ur passing.

                 

                The pre populate values are goin out after saved pdf open in reader, because code is like this

                // start by clearing the values first
                this.rawValue = null;

                if pdf not in browser it never reach inside to get new values bcz there is no url to parse for valuse and it will clear the valuse on initialize event.
                 
                also save the pdf as dynamic rather static.