Step by step howto – display a warning before leaving site


Sometimes there is an audit requirement, to let customers know a link is off your site and therefore you take no further responsibility for it. For example, a reference to an external associate site.



I’ve just used some simple javascript code, which is triggered by the click (onclick event). This pops up a warning, which can be accepted or rejected. Accepting goes to the desired site, whilst reject just aborts.



Or you can see it in its own page here: demo of accepting to leave a site

Here is the source code of the link:

function Terms() {'/common/demoP/popup.html','windowName','width=500,height=300');
    if (!popup.opener) popup.opener = self;

Hi there - below you'll see a link to  When you click it, a popup will appear that you need to accept to follow the link.

<a href="#" onClick="Terms()">

Here is the source of the popup:

function supressError() { return true; }

function load(url) { window.onerror = supressError;
    opener.location.href = url;

Warning you are about to leave my cool site,
only click 'Leave' if you absolutely want too! <form> <input type=submit value="Don't Leave!" onClick="javascript:self.close()"> <input type=submit value="Leave" onClick="javascript:load('');self.close()"> </form>


If you have found my website useful, please consider buying me a coffee below 😉

One Reply to “Step by step howto – display a warning before leaving site”

  1. Hi Jason,

    You should be able to just add the onclick routine, to the link for youtube.



    Hi WaltDe,

    Glad you like it. Most of my posts are as a result of quite a few hours, debugging, testing and devising – for a given problem.

    Also I’ve got a host of free online tools, that I use daily here: – for encryption, graphing, image generation, etc.



Leave a Reply

Your email address will not be published. Required fields are marked *