0

Currently working on a JavaScript on a SharePoint home page.

The script below will popup a window that shows a message: "Welcome to new page."

However, it is going to be annoying if it appears every single time user go to the page.

Is there a way to show the popup only once for per user each session?

<script language="javascript" type="text/javascript"> 
ExecuteOrDelayUntilScriptLoaded(yourFunction, 'SP.js'); 
function CloseCallback()
{
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel);
} 
function yourFunction() 
{ SP.UI.ModalDialog.showWaitScreenWithNoClose('Welcome to the new site'); 
setTimeout(function() { CloseCallback(); }, 2000); }
 _spBodyOnLoadFunctionNames.push("yourFunction()"); </script>   
0

You can make use of sessionStorage to store data per browser session.

Do try and modify the below code:

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

ExecuteOrDelayUntilScriptLoaded(yourFunction, 'SP.js'); 

function CloseCallback()
{
    SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel);
} 

function yourFunction() 
{   
    //check if session storage exists and also check if session storage contains an item with `some_key`
    if(window.sessionStorage && window.sessionStorage.getItem("some_key")){ 
        console.log("already loaded");
    }else{
        //set value in session storage
        window.sessionStorage.setItem("some_key", "first_load_screen");
        SP.UI.ModalDialog.showWaitScreenWithNoClose('Welcome to the new site'); 
        setTimeout(function() { CloseCallback(); }, 2000);  
    }
}

_spBodyOnLoadFunctionNames.push("yourFunction"); 

</script>   
  • Correct answer, thanks a lot for your help! It works! – John Lee Nov 28 '17 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.