These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Document close on alert box value.

MFARRELL
Registered: Aug 17 2010
Posts: 17

/*********** belongs to: Page-Actions:Page1:Page Open:Action1 ***********/
var cMsg = "Continuing with the current action will overwrite previous entries";
cMsg += "\n\nDo you want to continue?";

var nRtn = app.alert(cMsg,2,2,"Question Alert Box");
if(nRtn == 2)
{app.execMenuItem("Close")}

For some reason i cannot get this to work. I just want a script that on page open displays a message and if the user selects no it closes the PDF.

This runs everything but the menu item.

Thanks.

try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
It's not a good idea to try to close the document from a page event.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

MFARRELL
Registered: Aug 17 2010
Posts: 17
Why is that?

And do you suggest any other way to do it?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Acrobat JavaScript is an interpreted language, that is, each time a given script is called the code is reevaluated and run. Because each line is checked and processed in real time, closing the file in which the script resides will close the script, but the line pointer will still be active and point to line in a PDF that is no longer open or in memory. Sort of like reading the instructions about disconnecting electric power and in doing so you kill the electricity to the light you are using to read the instructions.

You cold try an application folder level script, but you will probably need to provide the doc object to be closed. You may even need to have at least one other PDF open.

George Kaiser