Enhancement of the beforeLinkClicked function