Legacy Knowledge Base
Published Sep. 10, 2025

JavaScript code in Link to URL page gets executed

Written By

Peter Nyiro

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • When creating a new public page of type "Link to URL" and using JavaScript code as the URL, the code gets executed when accessing the page.

Environment

  • Liferay DXP 2025.Q1 and prior Quarterly Releases

Resolution

  • This behavior is by design. The JavaScript code in the URL field is treated as a valid URL and rendered within an anchor tag. This is the default browser behavior when handling JavaScript URLs within anchor tags.
  • While Liferay has addressed this in later versions, to mitigate this in prior versions, implement a Content Security Policy (CSP) to prevent the execution of inline JavaScript. This policy can restrict the sources from which scripts are allowed to load, enhancing security.

Additional Information

 

Did this article resolve your issue ?

Legacy Knowledge Base