Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How give error message if more than one pdf open

Explorer ,
Jun 06, 2017 Jun 06, 2017

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

TOPICS
Acrobat SDK and JavaScript , Windows
890
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 07, 2017 Jun 07, 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...)

Translate
LEGEND ,
Jun 07, 2017 Jun 07, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 07, 2017 Jun 07, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2017 Jun 07, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2017 Jun 07, 2017

You are right.  This was a typo.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2017 Jun 07, 2017

You can get the active document with app.doc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2017 Jun 07, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2017 Jun 07, 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...)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2017 Jun 07, 2017
LATEST

Yes, that did the trick!  TY so much!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines