Created
March 10, 2017 12:04
-
-
Save tomazursic/b850f921e8d1b11079ab6b0a20ee3d2f to your computer and use it in GitHub Desktop.
Warning when opening external links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
var root = new RegExp(location.host); | |
$( 'a' ).each(function() { | |
if( location.hostname === this.hostname || !this.hostname.length ) { | |
$(this).addClass('local'); | |
} else { | |
$(this).addClass('external'); | |
} | |
}); | |
$('a.external').on('click', function(e){ | |
e.preventDefault(); | |
var notify = confirm( | |
"You are about to leave the website of [COMPANY] and view the content of an external website. " + | |
"[COMPANY] cannot be held responsible for the content of external websites.\n\n" + | |
"Destination: " + $(this).attr('href') | |
); | |
if (notify){ | |
window.location = $(this).attr('href'); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment