Here is my problem. I’m working within a CMS and users are able to create hyperlinks (both internal and external) I’m wondering if there is a good way to check when a user clicks a link if they are navigating to an external site. I don’t want to do anything if they use the back/forward buttons, type something into the address bar, etc. I just want to redirect them to a page within our site that takes the address they REALLY want to go to in he query string and display a 5 second (or so) message telling them they are leaving our site and we aren’t responsible for what is there etc etc. Since end users will be responsible for generating most of the links, teaching them to actually point links at the intermediate page is less than ideal so I was wondering if there is an easy solution using javascript.
Share
You could use jQuery to attach a click event for all links on your site that are external (start with http, minus some special cases), which could then either show a modal dialog, or set
window.locationto your intermediate page (you can tack on a query string var for the external url). You can make a custom selector to get external links, then attach the behavior: