Copy link to clipboard
Copied
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
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...)
Copy link to clipboard
Copied
If you look at other examples of if statements you will see they have brackets. These are not optional. See JavaScript If...Else Statements
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You are right. This was a typo.
Copy link to clipboard
Copied
You can get the active document with app.doc.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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...)
Copy link to clipboard
Copied
Yes, that did the trick! TY so much!!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now