Saturday, May 16, 2015

Disclaimer Popup in SharePoint 2010 or 2013

Having a disclaimer popup in SharePoint is something that is necessary for many businesses and their internal external web sites.  This is usually a mandate for legal requirements for tracking legal agreements.  Recently we had to add a disclaimer that upon agreement granted you access to the existing extranet site.  After reading the disclaimer users would either press ok or cancel.   

  • [Ok] allows you in the site, drops a cookie on your machine and grants you access to the entire site and sub-sites until the next year when the cookie expires.
  • [Cancel] will take you out of the site and request your login again.
  • The cookie will be active on all sites and sub-sites in SharePoint, any URL from the root.

In order to perform this you need to have the disclaimer JavaScript in every site and sub-site in the root zone.  This is accomplished by the path=/.  All you have to do is place this code in the default masterpage at the bottom in between the </body> and the </html> tags.  Change the disclaimer under the decision variable.  The popup will only occur once.  Special thanks to my friend Ed Goad and his book he wrote, Windows Server 2012 Automation with PowerShell Cookbook this inspired me to right this JAVA script.  Here is the code that I wrote that performs this activity.  Be sure to save check in and publish the masterpage if you are editing in SharePoint designer.

<script type="text/javascript" language="javascript">

var agreement = GetCookie();

// checks for cookie and displays disclaimer alert if new user

if (agreement == "") {

//Author: Tony Di Leonardo

var decision = confirm("DISCLAIMER: GOES HERE \n\nClick Ok if you agree to the disclaimer or click Cancel to close this window. \n");

if (decision == true) {

// writes a cookie

var oneMinute = 60 * 1000

var oneHour = oneMinute * 60

var oneDay = oneHour * 24

var today = new Date()

var nextXmas = new Date()

nextXmas.setMonth(11)

nextXmas.setDate(31)

if (today.getMonth() == 11 && today.getDate() > 31) {

nextXmas.setFullYear(nextXmas.getFullYear() + 1)

}

var expiredays = nextXmas.getTime() - today.getTime()

expiredays = Math.floor(expiredays/oneDay)

var exdate = new Date()

exdate.setDate(exdate.getDate() + expiredays)

document.cookie = "PartnerAgreement" + "=" + escape("Agree To Disclaimer") +

((expiredays == null) ? "" : ";path=/; expires=" + exdate.toGMTString())

}

else {

// redirect

window.location = "/_layouts/signout.aspx";

// or close the browser window

//window.opener='x';

//window.close();

}

}

// gets the Cookie if it exists

function GetCookie() {

if (document.cookie.length > 0) {

c_name = "PartnerAgreement";

c_start = document.cookie.indexOf(c_name + "=")

if (c_start != -1) {

c_start = c_start + c_name.length + 1

c_end = document.cookie.indexOf(";", c_start)

if (c_end == -1) c_end = document.cookie.length

return agreement = unescape(document.cookie.substring(c_start, c_end))

}

}

return "";

}

</script>


by Tony Di Leonardo via Everyone's Blog Posts - SharePoint Community

No comments:

Post a Comment