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

Document Action will close

Enthusiast ,
Dec 11, 2017 Dec 11, 2017

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

Best
Mohammad Hasanin
TOPICS
Acrobat SDK and JavaScript , Windows
2.4K
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 , Dec 11, 2017 Dec 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.

Translate
Community Expert ,
Dec 11, 2017 Dec 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.

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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

Thank  you

Best
Mohammad Hasanin
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 ,
Dec 11, 2017 Dec 11, 2017

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

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 ,
Dec 11, 2017 Dec 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”.

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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

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

Best
Mohammad Hasanin
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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

“do something and invert the result”. only if you use logic operators in comparing values between two arguments

Best
Mohammad Hasanin
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 ,
Dec 11, 2017 Dec 11, 2017

This is not correct. Where did you read this?

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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

i didn't, it some times happened to me when trying crazy things in Acro JS!

Best
Mohammad Hasanin
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 ,
Dec 11, 2017 Dec 11, 2017

Can you share a sample file?

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 ,
Dec 11, 2017 Dec 11, 2017

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.

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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

no it doesn't if you use it in a button

Best
Mohammad Hasanin
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 ,
Dec 11, 2017 Dec 11, 2017

Remove the beep lines and you will see what happens.

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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

not happened also after removing the Beep lines, I'm using Adobe Acrobat Pro DC

Version 2018.009.20044 

Best
Mohammad Hasanin
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 ,
Dec 11, 2017 Dec 11, 2017

What code do you use now?

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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

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(); 

Best
Mohammad Hasanin
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 ,
Dec 11, 2017 Dec 11, 2017

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.

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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

OK, but what about other option available ? i mean how to do it the right way ?

Best
Mohammad Hasanin
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 ,
Dec 11, 2017 Dec 11, 2017

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.

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
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

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

}

Best
Mohammad Hasanin
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 ,
Dec 11, 2017 Dec 11, 2017

Lines 10-17 can be removed. A button doesn't have a value, so they don't do anything, anyway.

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 ,
Dec 11, 2017 Dec 11, 2017
LATEST

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-

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 ,
Dec 11, 2017 Dec 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.

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 ,
Dec 11, 2017 Dec 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?

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 ,
Dec 11, 2017 Dec 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.

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