I would like to know if there is javascript or jquery code I can use to check if a link would redirect the current page, instead of a it opening a new webpage.
I am using ruby on rails and on my site there are links that redirect and links that open a new webpage. I need js that executes when a user clicks on any of the links, if the link redirects, it should prompt a confirmation message then executes the link to redirect.
The only ways I’m aware that a link can open a new page are:
Unfortunately, it can be extremely difficult to reliably determine through javascript inspection if these are going to happen. This is because you’ll need to perform reflection on the event chain to check the javascript code, and you’ll need to call the server (via ajax call) to check for a data attachment.
The simplest way to do this is to manually examine your own site and see where these are happening. Then modify the ‘click’ event to confirm before proceeding.