PDF Security & Access Issues

How to Run JavaScript When Clicking Text in a PDF

Camila MilosovichCamila Milosovich Nov 10, 2026 869 views

Question details

The user wants to trigger a JavaScript action or open a local folder by clicking specific arbitrary text within a PDF document.

How to Run JavaScript or Open Links by Clicking Text in a PDF
Product
PDF
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.
Before you start

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.

Solution 1Recommended

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.

1
Open your PDF editor

Launch your capable PDF editing software and open the document you wish to modify.

2
Select the Link or Button tool

Navigate to the 'Edit' or 'Form' tab, and choose the option to insert a 'Link' or a 'Button'.

3
Draw over the target text

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

4
Assign the action

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.

Use Link Annotations or Invisible Buttons Over Text
Security Warning: Attempting to open a local folder (e.g., C:\MyFolder) via JavaScript is deliberately blocked by standard PDF security models. Always use standard HTTP links or relative file paths for external navigation.
Edit PDFs Easily

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. 1. Open your PDF in WPS Office: Launch WPS Office and open your target PDF document from the home screen.
  2. 2. Navigate to the Edit tab: Click on the 'Edit' tab located on the top ribbon of the interface.
  3. 3. Insert a Link: Select the 'Link' tool and draw a bounding box precisely over the text you want users to click.
  4. 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.
Easily add hyperlinks and interactive clickable areas over standard PDF textHigh compatibility with standard PDF formats, Adobe Acrobat, and Microsoft Office filesLightweight, fast, and completely free to use for basic PDF reading and editingSecure viewing environment that protects your device from unauthorized local scripts
microsoft office alternative - wps office

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.