Copy link to clipboard
Copied
Hi ,
I'm trying to ask the user to change his mind if he didn't really want to exit from the (Opened PDF Doc),, so i go to Document Action at (Document will close) and write the following :
var cMsg = "Are you sure you want to close ?";
cMsg += "\n\n";
cMsg += "Contiunue ? \n\n ";
var nRtn = app.alert(cMsg,2,2,"Warning ! ");
if(nRtn == 4)
{// A yes Response
// Code for doing the thing you do on a yes
this.closeDoc();
}
else if(nRtn == 3)
{ // No Response
//event.value = 0; // assume do nothing
beep
!this.closeDoc();
}
else
{ //Unknown Response
beep
!this.closeDoc();
}
But the Above Code is Closing the Document even if the user hit yes or no? ho do i change it to not close the document if the user hit (No)... thanks for any tip
The script can't abort the file close command. The only way is if the user closes the file using a button you added to it, which executes this code. But if they click the X button or File - Close or Quit, the file will close, no matter what.
Copy link to clipboard
Copied
Hi ,
I'm trying to ask the user to change his mind if he didn't really want to exit from the (Opened PDF Doc),, so i go to Document Action at (Document will close) and write the following :
var cMsg = "Are you sure you want to close ?";
cMsg += "\n\n";
cMsg += "Contiunue ? \n\n ";
var nRtn = app.alert(cMsg,2,2,"Warning ! ");
if(nRtn == 4)
{// A yes Response
// Code for doing the thing you do on a yes
this.closeDoc();
}
else if(nRtn == 3)
{ // No Response
//event.value = 0; // assume do nothing
beep
!this.closeDoc();
}
else
{ //Unknown Response
beep
!this.closeDoc();
}
But the Above Code is Closing the Document even if the user hit yes or no? ho do i change it to not close the document if the user hit (No)... thanks for any tip
The script can't abort the file close command. The only way is if the user closes the file using a button you added to it, which executes this code. But if they click the X button or File - Close or Quit, the file will close, no matter what.
Copy link to clipboard
Copied
The script can't abort the file close command. The only way is if the user closes the file using a button you added to it, which executes this code. But if they click the X button or File - Close or Quit, the file will close, no matter what.
Copy link to clipboard
Copied
Thank you
Copy link to clipboard
Copied
Info: !this.closeDoc(); will also close the document.
Copy link to clipboard
Copied
Very inventive but very wrong too! In fact it tries to close it twice (once because it’s going to close anyway and once be you call this.closeDoc.) This could even cause a crash.
! something does not mean “don’t do something” it means “do something and invert the result”.
Copy link to clipboard
Copied
it work good in a button with no crash, what do you suggest instead using !this.closeDoc()
Copy link to clipboard
Copied
“do something and invert the result”. only if you use logic operators in comparing values between two arguments
Copy link to clipboard
Copied
This is not correct. Where did you read this?
Copy link to clipboard
Copied
i didn't, it some times happened to me when trying crazy things in Acro JS!
Copy link to clipboard
Copied
Can you share a sample file?
Copy link to clipboard
Copied
All "!" does is take a Boolean value and return it after applying the NOT logical operator on it. It does not execute (or not execute) anything by itself. You give it a value of TRUE and it will return FALSE. You give it FALSE, it will return TRUE. That's it.
Copy link to clipboard
Copied
no it doesn't if you use it in a button
Copy link to clipboard
Copied
Remove the beep lines and you will see what happens.
Copy link to clipboard
Copied
not happened also after removing the Beep lines, I'm using Adobe Acrobat Pro DC
Version 2018.009.20044
Copy link to clipboard
Copied
What code do you use now?
Copy link to clipboard
Copied
var cMsg = "Are you sure you want to close ?";
cMsg += "\n\n";
cMsg += "Contiunue ? \n\n ";
var nRtn = app.alert(cMsg,2,2,"Warning ! ");
if(nRtn == 4)
{// A yes Response
// Code for doing the thing you do on a yes
this.closeDoc();
}
else if(nRtn == 3)
{ // No Response
//event.value = 0; // assume do nothing
!this.closeDoc();
}
else
{ //Unknown Response
!this.closeDoc();
}
Copy link to clipboard
Copied
medos20 wrote
var cMsg = "Are you sure you want to close ?"; cMsg += "\n\n"; cMsg += "Contiunue ? \n\n "; var nRtn = app.alert(cMsg,2,2,"Warning ! "); if(nRtn == 4) {// A yes Response // Code for doing the thing you do on a yes this.closeDoc(); } else if(nRtn == 3) { // No Response //event.value = 0; // assume do nothing !this.closeDoc(); } else { //Unknown Response !this.closeDoc(); }
This code will always close the document.
Copy link to clipboard
Copied
OK, but what about other option available ? i mean how to do it the right way ?
Copy link to clipboard
Copied
medos20 wrote
OK, but what about other option available ? i mean how to do it the right way ?
To not close the file? Simply do nothing. Assuming the code is executed from a button it will just return to the file as normal.
Copy link to clipboard
Copied
The Correct Code will be :
var cMsg = "Are you sure you want to close ?";
cMsg += "\n\n";
cMsg += "Contiunue ? \n\n ";
var nRtn = app.alert(cMsg,2,2,"Warning ! ");
if(nRtn == 4)
{// A yes Response
// Code for doing the thing you do on a yes
this.closeDoc();
}
else if(nRtn == 3)
{ // No Response
event.value = 0; // assume do nothing
}
else
{ //Unknown Response
event.value = 0; // assume do nothing
}
Copy link to clipboard
Copied
Lines 10-17 can be removed. A button doesn't have a value, so they don't do anything, anyway.
Copy link to clipboard
Copied
The Doc/WillClose event is triggered before a document is closed. However, it does not listen to the rc return code.
You won't be able to stop the document from closing.
J-
Copy link to clipboard
Copied
The clue is in the action name. It's called "Will close" not "Might close" or "Your chance to not close". Most actions with "Will" in the name are already committed.
Copy link to clipboard
Copied
“do something and invert the result”. only if you use logic operators in comparing values between two arguments
No, you are wrong. It inverts the result and (since it is not tested) throws it away. Where on earth did you get the idea that you can use this to cancel anything at all, still less a call already under way?
Copy link to clipboard
Copied
That seems valid but NOT valid when run as a document-will-close action where it will not stop the document closing and might cause a crash.
Copy link to clipboard
Copied
Yes, the final code is for button only