Here's the current situation:
- I have developed a web application that operates within a single HTML page named
myapp.req
. The content is dynamically exchanged using AJAX requests. - Users can access the application externally by following a link like
myapp.req?id=123
, which triggers the opening of a tab displaying the item with ID 123. - Most of the content on the page consists of user-generated material, often containing links to internal pages like
myapp.req?id=123
. - The issue arises when users click on these internal links. The browser reloads and erases all previously loaded content or user activity.
What I aim for is to intercept clicks on links leading to myapp.req?id=123
without reloading the entire page. Instead, I want to open the relevant tab (e.g., item 123) while preserving any other existing content or state. When users click on links directing them to external websites, normal navigation behavior should occur.
Therefore, my main question is: Is it possible to implement a global link handler that can determine if specific link clicks should trigger JavaScript execution without navigating away from the current page?
While I am aware that I could individually add event listeners to each <a>
element, I hope for a solution where setting up the listener once would suffice, eliminating the need to add handlers every time new content is loaded onto the page. Considering the various methods through which content is loaded, it would be impractical to modify code at all those entry points.
Does this explanation clarify the scenario?