Skip to main content
Known Participant
June 7, 2017
Answered

How give error message if more than one pdf open

  • June 7, 2017
  • 2 replies
  • 1018 views

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

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...)

2 replies

Bernd Alheit
Community Expert
Community Expert
June 7, 2017

You can get the active document with app.doc.

suemo22Author
Known Participant
June 7, 2017

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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 7, 2017

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...)

Legend
June 7, 2017

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

Legend
June 7, 2017

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.

try67
Community Expert
Community Expert
June 7, 2017

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.