JavaScript code in Link to URL page gets executed
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
learn-legacy-article-disclaimer-text
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.
did-this-article-resolve-your-issue