Skip to main content
Inspiring
Mar 27, 2017 12:16 PM UTC
Answered

Is there an alternative to the global object?

I've just read this very helpful article:

https://acrobatusers.com/tutorials/global-object-acrobat-javascript

... and in particular the security implications of the global object.

I've used the global object to pass variables between scripts within the same PDF document.

Is there an alternative to the global object for this purpose?

Many thanks,

David

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Mar 27, 2017 1:03 PM UTC

Yes, you can use a variable that is defined at the doc-level. It will be accessible to all scripts that run within that document.

5 replies

Joel Geraci
Community Expert
Community Expert
Mar 28, 2017 3:45 PM UTC

The persistent global object and variables defined at the document level have very different use cases. Remember that when you set variables at the document level, they travel with the document. That's not true of the persistent global object. They are not true alternatives to each other.

Translate
Inspiring
Mar 28, 2017 6:33 PM UTC

I was trying to work out why I went the global route ages ago.

I appreciate the comments re. different use cases.

Many thanks to all,

David

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Mar 27, 2017 1:03 PM UTC

Yes, you can use a variable that is defined at the doc-level. It will be accessible to all scripts that run within that document.

Translate
Inspiring
Mar 28, 2017 12:59 PM UTC

I seem to recall that with earlier versions, probably 7 and earlier, document variables were not persistent. Hence the use of global variables. I've changed the JavaScripts to use document variables. Everything seems to work fine, including persistence, and there are no security issues.

Translate
Bernd Alheit
Community Expert
Community Expert
Mar 27, 2017 12:52 PM UTC

In a document use simple variables.

Translate