Skip to main content
Inspiring
March 27, 2017
Answered

Is there an alternative to the global object?

  • March 27, 2017
  • 3 replies
  • 732 views

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 has been closed for replies.
Correct answer try67

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.

3 replies

Joel Geraci
Community Expert
Community Expert
March 28, 2017

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.

Inspiring
March 28, 2017

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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 27, 2017

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.

Inspiring
March 28, 2017

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.

Bernd Alheit
Community Expert
Community Expert
March 27, 2017

In a document use simple variables.