/* * Due to some of the "legal" changes in the handling of external links to the corporate website, a set of * controls needed to be added to warn users when exiting to 3rd party websites and/or content. * See: Jira CRP-172 sub task CRP-169 MJF * Code constructed by Derek Winfield and executed by Michael Farnham 05/03/2007 */ var monotypeExternalLinks = function () { var internalDomain = "www.faces.co.uk"; var confirmationMessage = "You are leaving the Faces website. You may return to the Faces website\nby closing the window to the third-party website\nthat you have opened\n\nDo you wish to continue?"; function markExternalLinks() { var pattern = new RegExp("^\\w+:\\/\\/(\\w+\\.)?(test)?" + internalDomain + "\\/"); var links = document.getElementsByTagName("a"); var addConfirm = false; for (var i = 0; i < links.length; i++) { //alert( links[i].href+":"+links[i].href.search("http") ); addConfirm = false; //found a link without our domain, and it's not a mailto if (!pattern.test(links[i].href) && links[i].href.substring(0, 7) != "mailto:") { addConfirm = true; } //check its not an internal link if( addConfirm && links[i].href.search("http") == -1 ) { //we didnt find an http in the href if( links[i].onclick ) { if( links[i].onclick.toString().search("http") == -1 ) { //the onclick doesnt have an http, its an internal link addConfirm = false; } }else{ //and there's no onclick, dont add the confirm addConfirm = false; } } if (addConfirm) { /*Following line added to make every non specified link open in a new window*/ /*links[i].setAttribute('target','_blank');*/ addListener(links[i], "click", confirmExit); } } } function confirmExit(e) { if (!confirm(confirmationMessage)) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } return false; } else { window.blur(); return true; } } var addListener = function() { if ( window.addEventListener ) { return function(el, type, fn) { el.addEventListener(type, fn, false); }; } else if ( window.attachEvent ) { return function(el, type, fn) { var f = function() { fn.call(el, window.event); }; el.attachEvent('on'+type, f); }; } else { return function(el, type, fn) { element['on'+type] = fn; } } }(); addListener(window, "load", markExternalLinks, false); }();