16 Replies Latest reply on Mar 25, 2009 1:58 PM by try67

    Java Script for cookie

    jmflynn
      I have some java script that I use in my html pages to check for a cookie
      before opening a file. I'm having trouble getting it to work inside of my PDF Files, any ideas. I placed it in the file

      Select Triger PAGE OPEN



      Any input on why it doesn't work

      Thanks,,
      John Flynn
        • 1. Re: Java Script for cookie
          jmflynn Level 1
          Java Script for cookie

          John Flynn - 01:06pm Mar 20, 2009 Pacific

          I have some java script that I use in my html pages to check for a cookie
          before opening a file. I'm having trouble getting it to work inside of my PDF Files, any ideas. I placed it in the file

          Select Triger PAGE OPEN
          Java Script for cookie

          John Flynn - 01:06pm Mar 20, 2009 Pacific

          I have some java script that I use in my html pages to check for a cookie
          before opening a file. I'm having trouble getting it to work inside of my PDF Files, any ideas. I placed it in the file

          Select Triger PAGE OPEN



          Any input on why it doesn't work

          Thanks,,
          John Flynn

          Any input on why it doesn't work

          Thanks,,
          John Flynn
          • 2. Re: Java Script for cookie
            try67 MVP & Adobe Community Professional
            The JavaScript that works in webpages and the one that works in PDF files are very different. There's no such thing as "Select Triger PAGE OPEN" in PDF files. You should consult the Acroabt JavaScript Reference before creating JS scripts for Acrobat.
            • 3. Re: Java Script for cookie
              jmflynn Level 1
              Thanks
              let me try again
              I open the PDF.then I go to Page Properties. Actions.
              There is an option inside-> ADD ACTIONS-> Select Trigger and then a selection for -> Open Page or Close Page.
              Then an option to Select an Action: (I select Run Java Script) and then ADD.
              Then I copy and paste the Script into the editor and click OK.
              The idea is for the PDF to run the script and check for the cookie, if the cookie is not found the user should be sent to a login page.
              When I try to paste the script into these messages it disappears.I'll try again ->



              Thanks for your help
              • 4. Re: Java Script for cookie
                try67 MVP & Adobe Community Professional
                Ah, OK, it's clearer now... but my remark still stands. JavaScript in HTML pages is not the same as the one in Acrobat.

                Could you post here the script that you're trying to use in the PDF?
                • 5. Re: Java Script for cookie
                  jmflynn Level 1
                  Everytime I try to paste it in it disapears EX..
                  I will paste in between these 888888's


                  88888888,,,,

                  Do you have an email,,, I'm a little behind on this ..

                  Thanks John Flynn
                  • 6. Re: Java Script for cookie
                    Patrick Leckey Level 3
                    John,

                    try67 is right - you can't mix the two JavaScript sandboxes.

                    In order to read the browser cookies inside your PDF, you will need to use the hostContainer object to pass information from your browsers JS context into the PDF and vice versa.
                    • 7. Re: Java Script for cookie
                      try67 MVP & Adobe Community Professional
                      John, you can get my email address by clicking on my user-name, but you might get some more help if you post it here.
                      • 8. Re: Java Script for cookie
                        jmflynn Level 1
                        I can't get the following code to work inside a PDF ANY Help

                        'b
                        'b
                        • 9. Re: Java Script for cookie
                          Patrick Leckey Level 3
                          John,

                          Nobody can see the code you are posting - it doesn't show up. We can't help you if we can't see what you're doing.

                          If this is JavaScript copied from an HTML page, please make sure you remove any HTML tags such as the <script> tags and the <!-- comment tags. If you leave those in, your code won't show up (it also won't run in Acrobat, since those are specific to HTML).
                          • 10. Re: Java Script for cookie
                            Patrick Leckey Level 3
                            Here is the code John is trying to post.

                            John, you left the HTML <!-- --> comment tags around it, which is why it would not display.

                            function getCookieVal (offset) {
                            var endstr = document.cookie.indexOf (";", offset);
                            if (endstr == -1)
                            endstr = document.cookie.length;
                            return unescape(document.cookie.substring(offset, endstr));
                            } function GetCookie (name) {
                            var arg = name + "=";
                            var alen = arg.length;
                            var clen = document.cookie.length;
                            var i = 0;
                            while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var favorite = GetCookie('loginTemp');
                            if (favorite == null) { window.location.href = 'member_log_in.html'; } function checkform() { if(window.document.guestform.FNAME.value.length == 0) {
                            alert("Please enter your first name.");
                            return false;
                            } else if (window.document.guestform.LNAME.value.length == 0) {
                            alert("Please enter your last name.");
                            return false;
                            } else if (window.document.guestform.CNAME.value.length == 0) {
                            alert("Please enter your company name.");
                            return false;
                            } else if (window.document.guestform.EMAIL.value.length == 0) {
                            alert("Please enter your e-mail address.");
                            return false;
                            } else {
                            return true;
                            }
                            }

                            This code will not run in Acrobat, because it makes reference to many Browser-specific JavaScript objects such as "window" and "document". There are NOT part of base JavaScript, they are objects provided to JavaScript running in HTML by your browser.

                            It's not a matter of "modifying" the above to work in Acrobat. You would need to completely re-write it.

                            John, please see this link for an example of using the hostContainer to have a PDF communicate with the HTML page it is embedded in:
                            http://www.windjack.com/WindJack/Browser2PDF/brwsr2acroJS.htm
                            • 11. Re: Java Script for cookie
                              jmflynn Level 1
                              Hi Thanks,
                              Do you think it is possible to rewrite the Java code in the PDF to make it check for the cookie before opening the the PDF File.

                              John
                              • 12. Re: Java Script for cookie
                                Patrick Leckey Level 3
                                Before opening the PDF file? No. Some of the JavaScript required to receive the cookie data from the HTML page is contained within the PDF file, so it will not execute until the PDF is loaded.

                                If you are looking for a DRM-style solution, you need to look at Adobe LiveCycle Rights Management Server ES or at designing a plug-in in C/C++. JavaScript is not suitable for document protection by any means.
                                • 13. Re: Java Script for cookie
                                  try67 MVP & Adobe Community Professional
                                  John, maybe you should explain what it is you want to achieve.
                                  It's possible there's another way to do it without having to read the cookie.
                                  • 14. Re: Java Script for cookie
                                    jmflynn Level 1
                                    I have a members only section in a web site users must login to access the contents. It contains a large amount of PDF Files and I want to restrict their access by Non members. Even if the file inadvertantly comes up on a google search or, a existing member copies and pastes the url into an email, I would like the file not to open unless the end user is properly loggedd into the site. Right now any end user that has the path to a PDF in site can open it.

                                    Thanks For all your help

                                    John
                                    • 15. Re: Java Script for cookie
                                      Bernd Alheit Adobe Community Professional & MVP
                                      Use a DRM software like 'Adobe LiveCycle Rights Management':
                                      http://www.adobe.com/products/livecycle/rightsmanagement/
                                      • 16. Re: Java Script for cookie
                                        try67 MVP & Adobe Community Professional
                                        You can encrypt the PDF file and send the password to your members by email, or display it in a secured HTML page.