<script language="javascript" type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', MyPopUp);
function createCookie(name,value,days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
}
else {
expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
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;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
function MyPopUp() {
var options = { url: '/ict-services/Pages/the-rule.aspx', title: '10 Day Rule', width: 800, height: 600 };
var visited = readCookie('visited');
if (!visited || visited !== "true") {
createCookie('visited', "true", 1);
SP.UI.ModalDialog.showModalDialog(options);
}
}
_spBodyOnLoadFunctionNames.push("MyPopUp()");
</script>
I need a modal dialog which will load as shown in the code below.
<script language="javascript" type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', yourFunction);
function yourFunction() {
var options = { url: '/_layouts/viewlsts.aspx', title: 'Title,Description, and Icon', width: 640, height: 400 };
SP.UI.ModalDialog.showModalDialog(options);
}
_spBodyOnLoadFunctionNames.push("yourFunction()");
</script>
The script has to be written in such a way that the popup appears once a day. An example would be appreciated.
Ok...my update script including cookie that expires after I minute (this is for testing purposes - will change to 7 days on production)
<script language="javascript" type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', MyPopUp);
function createCookie(name,value,days) { var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
}
else { expires = ""; }
document.cookie = name+"="+value+expires+"; path=/"; }
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; }
function eraseCookie(name) {
createCookie(name,"",-1); }
function MyPopUp() {
var options = { url: '/new.aspx', title: 'new title', width: 800, height: 600 };
var visited = readCookie('visited'); if (!visited || visited !== "true") {
createCookie('visited', "true", 1);
SP.UI.ModalDialog.showModalDialog(options); }
}
_spBodyOnLoadFunctionNames.push("MyPopUp()");
</script>