////////////////////////////// // VARIABLES ////////////////////////////// var propWindow; var survWindow; var homeDomain = 'www.telstrabusiness.com'; var externalTarget = true; var requestAgain = false; var propWidth = 301; var propHeight = 305; var propURL = '/business/popup/surveyRequest.jsp'; var propWinProps = 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0'; var propWinName = 'proposalWindow'; var survWidth = 725; var survHeight = 725; var survURL = ''; var survWinProps = 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1'; var survWinName = 'surveyWindow'; var survFreq = 10; var survDay='30'; var today = new Date(); var setDay = new Date(); setDay.setDate(today.getDate() + Number(survDay)); ////////////////////////////// // MAIN ////////////////////////////// jQuery.noConflict(); function onLoad() { // After load we want to add js functions to all location changing elements to // prevent the survey request for internal location changes. editLinkOnClickEvent(); } // Use this to detect an external link to enable survey popup function editLinkOnClickEvent() { // attach onclick on to all internal links jQuery('a').click(function() { url = jQuery(this).attr('href'); if (isInternal(url)) { externalTarget = false; } }); // attach onsubmit on to all (internal) forms jQuery('form').submit(function() { url = jQuery(this).attr('action'); if (isInternal(url)) { externalTarget = false; } }); } // After unload we want to propose the survey but only for external links (in other // words, when users are leaving the site) function onUnload() { if (externalTarget) { propose(); } } // Set load and unload events jQuery(document).ready(function() { onLoad(); }); window.onbeforeunload = onUnload; ////////////////////////////// // UTILITY ////////////////////////////// function isInternal(url) { // CALLS TO JS if (url.startsWith('javascript:')) { // all js functions called from links in our application do not leave the site return true; } // ONCLICK LINKS if (url.startsWith('#') || url == '') { // these links probably have onclick attributes - they do not leave the site return true; } // ABSOLUTE LINKS if (url.startsWith('http')) { if (url.startsWith('http://' + homeDomain) || url.startsWith('https://' + homeDomain)) { return true; } else { return false; } } // All remaining URLs are relative ones, which are internal. return true; } String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)} function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } ////////////////////////////// // SURVEY ////////////////////////////// function propose() { previousResult = readCookie('survey'); previousExpires = readCookie('expiryday'); if (previousResult == 'accepted' || previousResult == 'declined') { //change all expire day from 2019 to current day + 30 days for old caches if(previousExpires == null) { if(previousResult == 'accepted') { document.cookie = 'expiryday=' + setDay + '; expires=Mon, 31-Dec-2029 23:59:59 GMT; path=/business'; document.cookie = 'survey=accepted; expires=' + setDay + '; path=/business'; } else { document.cookie = 'expiryday=' + setDay + '; expires=Mon, 31-Dec-2029 23:59:59 GMT; path=/business'; document.cookie = 'survey=declined; expires=' + setDay + '; path=/business'; } } // already offered //alert('alreay declined or accepted'); } else { //because the string read from the cookie is not in Date format, therefore it can not be compared with "today" var tempDate; if(previousExpires != null) { tempDate=new Date(previousExpires); } // only if popup window if the current day is greater then cookie expiry day if(previousExpires == null || tempDate < today) { // random number [1,100] pick = 1 + Math.floor(Math.random()*100); // with freq >= 1, vote ranges from [100, 1] vote = 1 + Math.floor(99 / survFreq); if (vote >= pick) { //alert('yeah! (pick=' + pick + ',vote=' + vote + ')'); // 1 Try a real, nice popup window if (!propWindow) { propWindow = window.open(propURL, propWinName, propWinProps + ',height=' + propHeight + ',width=' + propWidth + ',top=' + (screen.height-propHeight)/2 + ',left=' + (screen.width-propWidth)/2); } else { propWindow.focus(); } // 2 If that did not work, try a JavaScript confirm dialog. // (if the real popup fails to open there is probably a popup blocker present, so the survey popup will // be blocked as well. We hope that because people have seen the confirm dialog, they'll allow the // survey popup if the browser asks...) /*if (!propWindow) { if (window.confirm('We’re conducting a very short survey to help us improve your experience on the ' + 'Telstra Business website.\n\nIt shouldn’t take longer than 1 to 2 minutes to complete.\n\nWe ' + 'value your feedback, and would appreciate if you took a few moments to respond to some ' + 'questions.\n\nClick OK to participate or CANCEL to decline.\n\nIf you click OK and nothing ' + 'happens, make sure that you do not have your pop up blocker activated.')) { accept(); } else { decline(); } }*/ } else { //alert('no! (pick=' + pick + ',vote=' + vote + ')'); } } } }