Skip to main content
Known Participant
Jun 7, 2017 4:39 AM UTC
Answered

How give error message if more than one pdf open

Hi,

How can I write javascript could where user receives an error message (app.alert) if another pdf file is open?  My program only works if one pdf file is open.  When another is open, it does not work b/c it detects 2 active pdfs open instead of just one.  I want the user to be alerted to close the other pdf before proceeding.  The following did not work:

if event.target > 1

app.alert ("Close all pdfs before proceeding.",3);

else ...

Please suggest an alternative code. Thx.

S

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jun 7, 2017 7:49 PM UTC

Change:

if (d != 1)

To:

if (d.length>1)

(I assume you don't want to show this error message when no files are open...)

8 replies

Bernd Alheit
Community Expert
Community Expert
Jun 7, 2017 10:02 AM UTC

You can get the active document with app.doc.

Translate
suemo22Author
Known Participant
Jun 7, 2017 5:56 PM UTC

Hi,

So I tried the following code

var d = app.activeDocs;

if (d != 1)

{

app.alert ("close all pdfs before proceeding",3);

}

and had multiple documents open to see if alert window would come up but instead got the following error:

:

Notably, I am now getting this error even when only one pdf is open.  What am I doing wrong?

Do I need to embed in trusted function?

S

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Jun 7, 2017 7:49 PM UTC

Change:

if (d != 1)

To:

if (d.length>1)

(I assume you don't want to show this error message when no files are open...)

Translate
Legend
Jun 7, 2017 7:48 AM UTC

If you look at other examples of if statements you will see they have brackets. These are not optional. See JavaScript If...Else Statements

Translate
Legend
Jun 7, 2017 7:49 AM UTC

Also event.target is nothing to do with the number of open PDFs, I missed that ! Better to fix the problem with open PDFs than make the user close their other work.

Translate
try67
Community Expert
Community Expert
Jun 7, 2017 8:51 AM UTC

Agreed. If you really want to do it, though, the correct way is to look at the length of the activeDocs property of the app object.

If it's longer than one then there are multiple files opened at the moment.

Translate