These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Conditional Logic Detecting Viewing Source of PDF

hartmantroy
Registered: Dec 23 2009
Posts: 5

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. I'm using "if (event.target.external)" around the Javascript code, but it doesn't seem to be firing on the initialize event of the individual form field. Any help would be much appreciated.

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

this is an interesting task.
The solution (I found) is a bit tricky.

You need several things.

1. A form variable. To create one open "file > form properties > variables" and add a variable with the value "null".2. A script object with a function to readout the external property.
// Function to check the external propertyfunction ExternalViewer(){// If it is false (not viewed in a browser) set the global variable "FormRunsExternal" to NO...if (event.target.external == false){FormRunsExternal.rawValue = "NO";}// ...else set it ot YESelse{FormRunsExternal.rawValue = "YES";}}

3. A hidden button to execute the script you need if the form is viewed in a browser. In my example it changes the value of a text field.
// Call the function from the script objectCheckForm.ExternalViewer(); // if (FormRunsExternal.rawValue == "NO"){TextField.rawValue = "Adobe Acrobat/Reader";}if (FormRunsExternal.rawValue == "YES"){TextField.rawValue = "Web Browser with Reader Plug-Inn";}

4. A script in the dox ready event of your form to trigger the hidden button.
// Execute the click event of the button to fire its scriptxfa.form.resolveNode("Formular1.#subform.Button").execEvent("click");

Example:
[url]https://acrobat.com/#d=BgcbQhmR6CbeWZ2Ps9*ubw[/url]

By the way:
If you test the form from the preview in Designer, it will recognise an external viewer.
So you better save it first and then open it with Adobe Reader or a browser.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

hartmantroy
Registered: Dec 23 2009
Posts: 5
Thanks for the response. I'd like to see this in action before implementing it into my file, but I can't access your example. Is there another way you can get it to me?