Message presented you leave your site

This time,I present in JavaScript (Jquery) code that checks whether you leave your domain. If so - popup alert to informing you that you are leaving the domain

$(document).ready(function () {
    $("a").click(function(event) {
        // check if the target link is your.domain.com
        // if not will show alert message
        if (this.href.indexOf("your.domian.com") == -1) {
            if (this.href.startsWith("http")) {
                event.preventDefault();
                var linkLocation = this.href;
                alert('Note that you are directed to an external site does not belong to this site');
                window.open(linkLocation, '');
                return false;
            }
        }
    });

});


Of course, change the code from "your.domian.com" to your site.

thanks,
Roi

Comments

Popular posts from this blog

A sharepoint list view of the current month

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

Export SharePoint 2010 List to Excel with PowerShell