How to Run JavaScript When Clicking Text in a PDF
Question details
The user wants to trigger a JavaScript action or open a local folder by clicking specific arbitrary text within a PDF document.

- Product
- Device & OS
- not provided
- Scenario
- Attempting to make static PDF text interactive to trigger automated JavaScript actions, such as opening a local directory or file.
- Observed behavior
- Standard PDF text does not inherently support click events, and Acrobat's security model strictly blocks JavaScript from opening local folders.
Modern PDF readers enforce strict security protocols to prevent malicious scripts from accessing local system files. Ensure any linked web destinations or network files are safe before proceeding.
Use Link Annotations or Invisible Buttons Over Text
Because static text cannot trigger actions, you must overlay an interactive PDF object (like an invisible button or link) and assign a permitted action to it.
PDF text inherently lacks interactive click events. To achieve the effect of clicking text, you must place an invisible button or a link annotation directly over the target text.
Additionally, security restrictions in most PDF viewers block JavaScript from freely opening local system folders. To redirect users, you should use standard hyperlink actions to open web locations or approved network files instead.
Launch your capable PDF editing software and open the document you wish to modify.
Navigate to the 'Edit' or 'Form' tab, and choose the option to insert a 'Link' or a 'Button'.
Draw a rectangular bounding box directly over the specific word or phrase you want to make clickable. If you are using a button, set its visual appearance properties to 'Invisible' or 'Transparent'.
In the object's properties menu, go to the 'Actions' tab. Select 'Run a JavaScript' for safe, permitted scripts, or choose 'Open a web link' to redirect the user without triggering security blocks.

Add Interactive Links to Text Seamlessly with WPS PDF
WPS Office features a comprehensive PDF editor that allows you to easily overlay link annotations on any text, making your documents highly interactive without writing complex JavaScript code.
- 1. Open your PDF in WPS Office: Launch WPS Office and open your target PDF document from the home screen.
- 2. Navigate to the Edit tab: Click on the 'Edit' tab located on the top ribbon of the interface.
- 3. Insert a Link: Select the 'Link' tool and draw a bounding box precisely over the text you want users to click.
- 4. Set the Destination: Choose whether the link should open a specific URL, a local file, or navigate to another page within the same document, then click 'OK' to save.

Frequently Asked Questions
Why does Acrobat block my JavaScript from opening a local folder?
Opening local folders or files via JavaScript is restricted by standard PDF security protocols to prevent malicious documents from accessing, modifying, or executing unauthorized files on your computer.
Can I apply a click event directly to a single word in a PDF without adding objects?
No, standard PDF text does not natively support click events. You must draw an invisible link annotation or button precisely over that specific word to make it clickable.
Is there a way to bypass PDF security to open a local file?
While you cannot bypass the core security model, you can configure 'Trusted Locations' in your PDF reader's settings or use standard 'Open File' link actions (rather than JavaScript) for permitted file access.
Will my interactive PDF buttons work in web browsers?
Basic link annotations work in almost all PDF viewers, including web browsers like Chrome or Edge. However, complex JavaScript actions attached to buttons may only function properly in dedicated desktop readers like WPS Office or Adobe Acrobat.




