External Link Notification

JS notification when an external link is clicked.

by dhavaljani

HTML

<!-- Example for http://stackoverflow.com/a/21540096/1590427 -->
<a href="http://stackoverflow.com/a/21540096/1590427" target="_blank">Stack Overflow Answer</a>
<a href="http://jsfiddle.net/idrive/FFDuh/" target="blank">Internal Link</a>

JavaScript

jQuery('a').filter(function() {
    return this.hostname && this.hostname !== location.hostname;
  }).click(function(e) {
       if(!confirm("You are about to proceed to an external website."))
       {
            // if user clicks 'no' then dont proceed to link.
            e.preventDefault();
       };
  });