I know that I can use JavaScript (if enabled in the browser) to override a link's href. For example, Google does this all the time to track outbound links in their search result listings.
Let's say that I'm on example-sites.com, and I want to link to example-destinations.com, but I'm sending the users to example-tracking-and-filter-site.com to track and filter (block directing the user to adult websites) the links. The example-tracking-and-filter-site.com just records the information (and possibly presents a blocked notice) before redirecting the user to the specified url (unless its blocked).
I could use the following code:
<a href="http://www.example-destinations.com/" onmousedown="javascript:this.href='http://www.example-tracking-and-filter-site.com/track.php?url=http%3A%2F%2Fwww.example-destinations.com%2F';"onkeypress="javascript:this.href='http://www.example-tracking-and-filter-site.com/track.php?url=http%3A%2F%2Fwww.example-destinations.com%2F';">Link</a>
Both users with JavaScript and without would land on example-destinations.com, but users with JavaScript would seamlessly pass through example-tracking-and-filter-site.com first.
That works great and fine, but, let's pretend that example-tracking-and-filter-site.com is down for whatever reason, but the other two sites work just fine. User's with JavaScript would get a server error and would not end on example-destinations.com. That's bad.
Is it possible to modify the code to first "ping" or detect that example-tracking-and-filter-site.com is live and working, before modifying the link's href. If the script doesn't get a response within a specified time then link will not modified by the javascript and the user is sent to example-destinations.com directly.
Is a "ping" or detecting function a bad idea or even possible, or would something else be better suited. I'd really like something that would be quick, and unnoticeable to the user.
Thanks