How to Prevent a Custom Acrobat PDF Dialog from Closing on Cancel
Question details
The user needs to display a Yes/No confirmation prompt when 'Cancel' is clicked in an Acrobat JavaScript custom dialog, but the dialog closes before the prompt appears.

- Product
- Adobe Acrobat PDF (JavaScript)
- Device & OS
- not provided
- Scenario
- Developing or executing a custom JavaScript dialog inside a PDF document where an action needs explicit user confirmation before aborting.
- Observed behavior
- The built-in Cancel button terminates the custom dialog immediately, bypassing any additional JavaScript actions or confirmation prompts.
Ensure you have access to the JavaScript console and the source code of your custom PDF dialog script to modify the button configurations.
Replace the Built-in Cancel Button with a Custom Button
Because the built-in Cancel button forces an immediate exit, you must build a custom button to intercept the click and handle the confirmation logic programmatically.
In Adobe Acrobat's JavaScript API, clicking any built-in dialog button (like OK or Cancel) triggers an immediate exit command. This stops any other bound actions from occurring. To prompt users for confirmation before closing, you must eliminate the standard buttons and replace them with custom ones.
In your dialog descriptor object, remove the default 'ok_cancel' or 'cancel' button definitions from the elements array to prevent the built-in buttons from rendering on the screen.
Define a new button element within your dialog's array. Set its display name to 'Cancel' and assign it a unique 'item_id' (e.g., 'btnC') so you can reference it in your script.
In your dialog's function definition, create an event handler for your custom button. Inside this handler, use the 'app.alert' method to prompt the user with a Yes/No confirmation dialog.
Check the return value of 'app.alert'. If the user selects 'Yes', trigger 'dialog.end(value)' to manually close the custom dialog. If 'No', do nothing, which allows the custom dialog to remain open.

Need a powerful PDF editor and Office suite? Try WPS Office
While advanced JavaScript dialog scripting is highly specific to Adobe Acrobat, WPS Office provides a robust built-in PDF editor for reading, editing, and form filling. It serves as a comprehensive, lightweight, and completely free alternative for handling standard Office files and PDFs seamlessly.

Frequently Asked Questions
Why does the built-in Cancel button close the dialog immediately?
In Adobe Acrobat JavaScript, clicking the built-in Cancel or OK button inherently executes a forced close command before any other bound actions can occur. This hardcoded behavior ensures dialogs always have a guaranteed exit path.
Can I intercept the dialog window's top-corner 'X' close button?
No, the 'X' button in the title bar behaves identically to the built-in Cancel button. It forces an immediate termination of the dialog and returns a 'cancel' string, which cannot be intercepted by an app.alert confirmation.
How do I distinguish between OK and a Custom Cancel action in my main script?
When calling 'dialog.end(value)' inside your custom button handler, you can pass a specific string or integer value as an argument. This value is returned by the 'app.execDialog' function, allowing your main script to conditionally determine exactly how the dialog was closed.
Does WPS PDF support JavaScript for custom dialogs?
WPS PDF supports standard PDF form field calculations and basic JavaScript for data validation, but complex custom application-level dialogs (like 'app.execDialog') rely on Adobe Acrobat's proprietary API and may behave differently across third-party PDF readers.




