Jump to content

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

Recommended Posts

Hello,

I have a site on Squrespace. I have added an extenal link as a menu item. So, if anybody click on that menu item, he will visit to the external link. But I want that, if anybody click on that link, first he will get a warning message like "Leaving the current site" and then if he clicks on okay the will visit the linked external site. Is it possible that I can do in the website?

Thank You

Link to comment
  • Replies 1
  • Views 515
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Try Settings > Advanced > Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
  $('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>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.