Ok, so this is the best that I can come up with but it ain't pretty. 
Have all the links on the page point to another page (we'll call it redir.html). redir.html is passed a parameter via the URL that defines what page it should then open, like redir.html?page=www.example.com/something. redir.html then executes whatever JavaScript you want, perhaps only if it was opened in a new tab/window. This can be detected by checking to see if window.history.length === 1.
redir.html:
<script>
function getParameter(param) {
            var val = document.URL;
            var url = val.substr(val.indexOf(param))  
            var n=url.replace(param+"=","");
            return n;
}
var page = getParameter("page");
if(window.history.length === 1)
{
    alert("I opened in a new tab or window");
}
window.location.href = page;
</script>
Example anchor tag on source page:
<a href="redir.html?page=http://example.com/something">My link</a>
(I got the getParameter function from this SO post.)