You could remove the event handler when they're clicked:
var safeLinks = ['.test', '.test2', '.test3', '.test4', '.test5'];
function promptBeforeClose() {
return 'Are you sure you want to leave?';
}
$(window).on('beforeunload', promptBeforeClose);
$(document).on('click', safeLinks.join(', '), function(e) {
$(window).off('beforeunload', promptBeforeClose);
});
Also, if these safe links have a common ancestor, use that instead of document
as the delegation parent or people will complain. ;)