Skip to main content
MarkWalsh
Inspiring
June 28, 2016
Answered

Is there a way to access document scripts via javascript?

  • June 28, 2016
  • 2 replies
  • 1111 views

I know that I can add and remove a document script via name, but is there a way to access the actual content of the document script?

I have a script which I use in an action to finalize a lot of the forms I create (clears form, adds javascript requirement, validates and sets certain parameters, etc.), and I'd like to add an action to the document based on whether or not a certain function exists in the document level scripts. If I can access the code, I can parse it out to find out if the desired function exists or not, but I don't see a way to do this.

Is this possible?

This topic has been closed for replies.
Correct answer try67

If you know the name of the function you can use the typeof command to find out if it's declared or not.

For example:

function hello() {app.alert("Hello!");}

typeof hello; // returns "function"

typeof goodbye; // returns "undefined"

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 28, 2016

If you know the name of the function you can use the typeof command to find out if it's declared or not.

For example:

function hello() {app.alert("Hello!");}

typeof hello; // returns "function"

typeof goodbye; // returns "undefined"

MarkWalsh
MarkWalshAuthor
Inspiring
June 28, 2016

Thanks, that does what I'm looking for perfectly! And, even easier than having to parse the code myself.

MarkWalsh
MarkWalshAuthor
Inspiring
June 30, 2016

This only works for defined functions.

Not for code like:  

app.alert ("Hello!");

or

(function (){app.alert ("Hello");});();


That's a good point to know, although in my circumstance, the code I'm looking for will always be in defined functions.

Thanks

Inspiring
June 28, 2016

Not with JavaScript. Possible to create Plug-in using SDK and programming language.