Other PDF Issues

How to Prevent a Custom Acrobat PDF Dialog from Closing on Cancel

Maira MehtabMaira Mehtab Nov 5, 2026 870 views

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.

How to Prevent a Custom Acrobat Dialog from Closing on Cancel
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.
Before you start

Ensure you have access to the JavaScript console and the source code of your custom PDF dialog script to modify the button configurations.

Solution 1Recommended

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.

1
Remove Built-in Buttons

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.

2
Add a Custom Button Element

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.

3
Write the Button Action

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.

4
Conditionally Close the 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.

Replace the Built-in Cancel Button with a Custom Button
Variable Tracking: Since you are no longer using default return values, make sure to pass a specific return value in 'dialog.end("custom_cancel")' to help your main script distinguish between your custom cancel action and the OK action.
Free Microsoft Office alternative

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.

Seamlessly open, fill, and edit PDF documents without expensive subscriptions.Fully compatible with Microsoft Word, Excel, PowerPoint, and standard PDF formats.Lightweight software that runs extremely fast on both older and newer devices.Built-in tools for PDF conversion, form filling, electronic signatures, and annotations.
microsoft office alternative - wps office

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.