How to Redirect to a Link on a PDF Button Click Using JavaScript
Question details
The user wants to configure a button in a PDF document to open a specific web link using a JavaScript action.

- 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.
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.
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.
Right-click the button in your PDF editor's form editing mode and select 'Properties'.
Click on the 'Actions' tab at the top of the Properties dialog box.
From the 'Select Action' dropdown menu, choose 'Run a JavaScript' and click the 'Add' button.
In the JavaScript Editor, enter the code: window.open("https://www.example.com", "_blank"); and replace the example URL with your actual destination link.
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 the Same Window
If your goal is to have the web link replace the current PDF view entirely, you can use the this.submitForm method.
Use the Standard Open a Web Link Action
For standard PDF links without complex conditional logic, using the built-in hyperlink action is much simpler and safer than writing JavaScript.
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. Open the PDF: Launch WPS Office and open your PDF document.
- 2. Access Link Tools: Navigate to the 'Edit' tab on the top ribbon.
- 3. Insert the Link: Click 'Link' and select 'Add/Edit Web or Document Link'.
- 4. Define Link Area: Draw a box over your desired button or text, enter the target URL in the prompt, and click 'OK'.

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.




