How can i create a popup that automatically shows when the user visit the homepage? The user also want an option to not show the popup anymore.
Here is my code:
ExecuteOrDelayUntilScriptLoaded(initialize, "sp.js");
(function(){
function initialize() {
var context = new SP.ClientContext.get_current();
var web = context.get_current();
OpenPopUpPageWithTitle(url, callback, width, height, title)
}
window['initialize'] = initialize;
})();
_spBodyOnLoadFunctionNames.push("initialize");
My new code are:
On the startpage in a script editor:
<script type="text/javascript">
SP.SOD.executeOrDelayUntilScriptLoaded(initialize, 'sp.ui.dialog.js');
function initialize() {
var context = new SP.ClientContext.get_current();
var web = context.get_current();
var currentUser = web.get_userprofile.get_current();
var options = {
autoSize: true,
title: "My Custom dialog",
showClose: true,
allowMaximize: true
};
SP.UI.ModalDialog.commonModalDialogOpen("/_layouts/test.aspx",options,closecallback, null);
On the aspx page that popup shows:
<html>
function mDown(){
ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");
function runCode(){
var currentUser;
var context = new SP.ClientContext.get_current();
var web = context.get_web();
currentUser = web.get_currentUser();
context.load(currentUser);
context.executeQueryAsync(onSuccessMethod, onRequestFail);
function onSuccessMethod(sender, args) {
var account = currentUser.get_loginName();
var currentUserAccount = account.substring(account.indexOf("|") + 1);
// alert(currentUserAccount);
createCookie(account,"showPopUp",10);
readCookie(account);
//obj.style.backgroundColor="#1ec5e5";
//obj.innerHTML= currentUserAccount;
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var 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);
}
alert(nameEQ);
return null;
}
function onRequestFail(sender, args) {
alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
}
}
};
</script>
<body>
<button id="myButton" onClick="mDown()">Click me!</button>
</body>
</html>
How can i check if the user has the cookie on the startpage?
OpenPopUpPageWithTitle