0

I want to display a popup once the user opens the site for the first time. I am thinking of display jquery popup. But I have few question.

A- Do I add the code to display the popup in the master page? so when the user opens any page in the site it would display this popup?

B- When the user click, I accept. Where do I store his acceptance, so next time it won't appear to him?

0

We have this implemented in a few sites in SharePoint Online using a Custom Action stapled to the site. This would check on every page load, which ideally is what you want, otherwise people could bypass it entirely. You would want to put it in the master page or utilize a custom action if that is available to you, you didn't tag a version.

This is our implementation using plain old Javascript and storing the acknowledgement in a cookie, it's really up to you how you want to store the acceptance, it could write/update a list. This cookie expires after a day and they must confirm again or get kicked out.

document.addEventListener('DOMContentLoaded', function(){ 
        var agreed = document.cookie.replace(/(?:(?:^|.*;\s*)Acknowledged\s*\=\s*([^;]*).*$)|^.*$/, "$1");
        if(!agreed){
            var ack = confirm("NOTICE:Do you promise to adhere to the rules?");
            if (ack == true) {
                var d = new Date();
                var expire = new Date(d);
                expire.setDate(d.getDate() + 1);
                document.cookie = "Acknowledged=true; Path=/; Expires="+expire;
            } else {
                window.location.href="http://www.google.com";
            }
        }
    }, false);
  • Thanks Eric. But what if the users manually clears the cookies? What's the best practice to store this on the server? – Jacky Oct 19 '16 at 0:13
  • Also, is it right to keep checking on each page load? – Jacky Oct 19 '16 at 0:13
  • If they clear their cookies, the next time they hit the site, they get the prompt. It depends on how much you want to track whether or not you put it on a singular page or all pages. – Eric Alexander Oct 19 '16 at 0:50
0

I would suggest to create custom list with no column except default title column (Mandatory) and below settings from the advanced settings option:

List Advanced Settings

On master page, using REST api query the list.

  1. Item count == 0 : User have not accepted the terms. Show popup. On "Accept Term" click , just add new item in above created custom list with any value in title.
  2. Item count == 1 : As user can read there own created item only, item count ==1 means user have accepted the terms earlier. Do not show popup.

Pros :

  1. No need to save user name, created by column will take care of it.
  2. No need to compare the user name.
  3. Using the settings to read own items, will make the query execution faster.
  4. No need to compare specific column with current user login, just with result xml item count will do the required.
  5. No need to maintain item level permission in the list, reducing implementing of designer workflow / or other method.
  • Thanks Monica, this sounds amazing. But, should I keep checking this everywhere? How do I cache that the user accepted, and stop running the REST service everytime? – Jacky Oct 19 '16 at 15:10
  • Cache would mean temporary so that will not be fool proof option. Calling rest will be perfect solution. With the above mentioned method the execution time will not be longer. And you can check the acceptance only on home page and not on every page. For that you can add script editor / content editor instead of master page. – Monica Jagani Oct 20 '16 at 5:19

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.