Buy me a coffee

How to set up a warning message when visiting an external link?

To set up a warning message when visiting an external link, you can follow these steps.

#1. Use this code to Code Injection > Footer (or Page Header Injection, if you want to do this on specific page only)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
  $(document).ready(function(){
  $('a').on('click', function() {
   if ( this.host !== window.location.host ) {
      var thisHrefHere = this.href;

      if ( window.confirm("Hey! Warning. U Click another url: "+thisHrefHere+"") ) {
         console.log('Click true and redirecting');
      }else {
         console.log('Click false and no redirect');
         return false;
      }    
   }
});
  });
</script>

How To Set Up A Warning Message When Visiting An External Link 01 Min

#2. Result

How To Set Up A Warning Message When Visiting An External Link 02 Min

#3. To customize the text in warning message, you can adjust this line.

How To Set Up A Warning Message When Visiting An External Link 03 Min