Other PDF Issues

How to Redirect to a Link on a PDF Button Click Using JavaScript

Ayan MasoodAyan Masood Nov 5, 2026 870 views

Question details

The user wants to configure a button in a PDF document to open a specific web link using a JavaScript action.

How to Redirect to a Link on a PDF Button Click Using JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an interactive PDF form or document where clicking a specific button triggers a web URL to open via a custom JavaScript action.
Observed behavior
The user needs the correct JavaScript syntax to execute the URL redirection, either opening in a new tab or replacing the current window view.
Before you start

Ensure you have an advanced PDF editor like Adobe Acrobat Pro installed, as standard PDF readers do not allow you to edit form fields or add custom JavaScript actions.

Solution 1Recommended

Use JavaScript to Open a URL in a New Window

This is the most common method, utilizing the window.open function to launch the target URL in a new browser tab without closing the active PDF.

By opening the link in a new window, you ensure that the user does not lose their place or entered data in the current PDF document.

1
Open Button Properties

Right-click the button in your PDF editor's form editing mode and select 'Properties'.

2
Navigate to the Actions Tab

Click on the 'Actions' tab at the top of the Properties dialog box.

3
Add a JavaScript Action

From the 'Select Action' dropdown menu, choose 'Run a JavaScript' and click the 'Add' button.

4
Insert the Code

In the JavaScript Editor, enter the code: window.open("https://www.example.com", "_blank"); and replace the example URL with your actual destination link.

5
Save and Test

Click 'OK', close the Properties window, and save your document. Exit form editing mode to test the button.

Use JavaScript to Open a URL in a New Window
Code Accuracy: Ensure you keep the quotation marks around your URL and the _blank parameter for the code to execute properly.
WPS PDF Editor

Easily Add Web Links to PDFs with WPS Office

While scripting provides advanced control, WPS PDF allows you to effortlessly insert clickable links into your documents without any coding. It is a lightweight, full-featured PDF tool that handles interactive elements seamlessly.

  1. 1. Open the PDF: Launch WPS Office and open your PDF document.
  2. 2. Access Link Tools: Navigate to the 'Edit' tab on the top ribbon.
  3. 3. Insert the Link: Click 'Link' and select 'Add/Edit Web or Document Link'.
  4. 4. Define Link Area: Draw a box over your desired button or text, enter the target URL in the prompt, and click 'OK'.
No coding required to add hyperlinks or interactive elements.Seamless compatibility with standard Adobe PDF formats.Lightweight, fast, and highly intuitive user interface.Cross-platform support for Windows, Mac, and mobile devices.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my JavaScript button not working in some PDF viewers?

Not all PDF viewers support JavaScript execution due to security restrictions. Browser-based readers or basic mobile PDF apps often block scripts. To ensure your links work everywhere, it is recommended to use the standard 'Open a web link' action instead.

Can I trigger the URL redirect based on a condition?

Yes. One of the main advantages of using JavaScript over a standard link is the ability to use if/else statements. You can validate other form fields first, and only execute the window.open command if specific conditions are met.

Is it safe to use JavaScript in PDFs?

JavaScript in PDFs can pose a security risk, which is why some users actively disable it in their Acrobat preferences. You should only use JavaScript when absolutely necessary for advanced form functionality, and ensure your document is distributed to trusted users.