Skip to main content
M.Hasanin
Inspiring
December 11, 2017
Answered

Document Action will close

  • December 11, 2017
  • 5 replies
  • 2871 views

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

This topic has been closed for replies.
Correct answer try67

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.

5 replies

Legend
December 11, 2017

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.

M.Hasanin
M.HasaninAuthor
Inspiring
December 11, 2017

Yes, the final code is for button only

Mohammad Hasanin
Legend
December 11, 2017

“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?

Legend
December 11, 2017

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.

Bernd Alheit
Community Expert
Community Expert
December 11, 2017

Info: !this.closeDoc(); will also close the document.

Legend
December 11, 2017

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

M.Hasanin
M.HasaninAuthor
Inspiring
December 11, 2017

it work good in a button with no crash, what do you suggest instead using !this.closeDoc()

Mohammad Hasanin
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 11, 2017

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.

M.Hasanin
M.HasaninAuthor
Inspiring
December 11, 2017

Thank  you

Mohammad Hasanin