SOLVED

Possible to create site collection disclaimer pop-up with SPFx?

%3CLINGO-SUB%20id%3D%22lingo-sub-179180%22%20slang%3D%22en-US%22%3EPossible%20to%20create%20site%20collection%20disclaimer%20pop-up%20with%20SPFx%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-179180%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3EI'm%20just%20getting%20started%20with%20SPFx%20and%20development%20and%20was%20wondering%20if%20you%20had%20any%20pointers%20for%20me%20regarding%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20SPO%2C%20we%20require%20some%20sort%20of%20disclaimer%20pop-up%20overlay%20(not%20simple%20js%20alert)%20that%20appears%20as%20soon%20as%20a%20user%20visits%20a%20certain%20site%20collection.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20something%20like%20this%20be%20achieved%20with%20SPFx%3F%20On%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fspfx%2Fextensions%2Foverview-extensions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fspfx%2Fextensions%2Foverview-extensions%3C%2FA%3E%20there's%20a%20note%20stating%20that%20there%20is%20a%20known%20bug%20with%20list%20and%20library%20extension%20support%20in%20the%20classic%20experiences.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20for%20your%20help%20getting%20me%20started.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-179180%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESPFx%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-539952%22%20slang%3D%22en-US%22%3ERe%3A%20Possible%20to%20create%20site%20collection%20disclaimer%20pop-up%20with%20SPFx%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-539952%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F135145%22%20target%3D%22_blank%22%3E%40Steve%20Johnson%3C%2FA%3E%26nbsp%3B%20that%20sounds%20really%20interesting!%20I%20need%20a%20pop-up%20on%20an%20entry-site%20(%22I%20declare%20I%20don't%20do%20this%20and%20that...%22).%20Can%20you%20send%20me%20(or%20post)%20the%20files%20you%20mentioned%20as%20well%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-179599%22%20slang%3D%22en-US%22%3ERe%3A%20Possible%20to%20create%20site%20collection%20disclaimer%20pop-up%20with%20SPFx%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-179599%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20is%20possible%20-%20I've%20done%20something%20similar%20(a%20cookie%20consent%20popup)%20within%20our%20organisation%20which%20requires%20us%20to%20display%20a%20popup%20overlay%20in%20the%20middle%20of%20the%20screen%2C%20notifying%20our%20users%20about%20our%20End%20User%20Policy%2C%20there's%20a%20link%20within%20the%20popup%20as%20well%20which%20takes%20them%20to%20that%20policy%20page.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20Classic%20site%20days%2C%20we%20had%20the%20code%20embedded%20within%20the%20Master%20Page%2C%20sadly%20that's%20not%20really%20an%20option%20with%20Modern%20Team%20Sites%2C%20so%20I%20refactored%20the%20code%20into%20an%20SPFx%20Web%20Part%20instead%20and%20what%20I%20did%20was%20to%20deploy%20it%20to%20all%20team%20sites%20via%20the%20App%20Catalog%20and%20the%26nbsp%3B%3CSPAN%3E%22skipFeatureDeployment%22%20switch%20in%20the%20package%20file%2C%20which%20then%20made%20it%20easier%20for%20me%20to%20deploy%20it%20via%20PnP%20framework.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThere%20are%20two%20dependencies%20in%20the%20cookieconsent%20JS%20and%20CSS%20files%20that%20need%20to%20be%20included%20(happy%20to%20send%20these%20to%20you)%20and%26nbsp%3BI've%20included%20a%20chunk%20of%20the%20TS%20code%20as%20well.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EI've%20not%20tested%20it%2C%20but%20you%20could%20set%20the%20cookieconsent%20part%20to%200%20days%20(from%20the%20cookieconsent%20JS%20file)%20to%20ensure%20the%20popup%20comes%20up%26nbsp%3Ball%20the%20time%26nbsp%3BI%20think.%20It%20might%20not%20be%20the%20best%20way%20to%20achieve%20your%20objective%2C%20but%20hopefully%20it's%20enough%20to%20get%20you%20started.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%20%20public%20render()%3A%20void%20%7B%0A%20%20%20%20%20%20require('.%2Fcookieconsent.min.js')%3B%0A%20%20%20%20%20%20require('.%2Fcookieconsent-min.css')%3B%0A%0A%20%20%20%20this.domElement.innerHTML%20%3D%20%60%0A%20%20%20%20%20%20%26lt%3Bdiv%20class%3D%22%24%7B%20styles.enduserPolicy%20%7D%22%26gt%3B%0A%20%20%20%20%20%20%20%20%26lt%3Bdiv%20class%3D%22%24%7B%20styles.container%20%7D%22%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%26lt%3Bdiv%20class%3D%22%24%7B%20styles.row%20%7D%22%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3Bdiv%20class%3D%22%24%7B%20styles.column%20%7D%22%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3Bspan%20class%3D%22%24%7B%20styles.title%20%7D%22%26gt%3BEnd%20User%20Policy%26lt%3B%2Fspan%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3Bp%20class%3D%22%24%7B%20styles.subTitle%20%7D%22%26gt%3BREQUIRED%20-%20PLEASE%20DO%20NOT%20REMOVE%26lt%3B%2Fp%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%26lt%3B%2Fdiv%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%26lt%3B%2Fdiv%26gt%3B%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%26lt%3B%2Fdiv%26gt%3B%20%0A%20%20%20%20%20%20%26lt%3B%2Fdiv%26gt%3B%60%3B%0A%0A%20%20%20%20%20%20window.addEventListener(%22load%22%2C%20function()%7B%0A%20%20%20%20%20%20%20%20window%5B%22cookieconsent%22%5D.initialise(%7B%0A%20%20%20%20%20%20%20%20%20%20%22palette%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22popup%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22background%22%3A%20%22%2300728f%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%3A%20%22%23ffffff%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22button%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22background%22%3A%20%22transparent%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%3A%20%22%23ffffff%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22border%22%3A%20%22%23ffffff%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%22position%22%3A%20%22bottom-left%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22message%22%3A%20%22Here's%20some%20text%20about%20policy%20stuff.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22dismiss%22%3A%20%22Understood!%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22link%22%3A%20%22End%20User%20Policy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22href%22%3A%20%22link%20here%22%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D)%7D)%0A%20%20%7D%0A%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Regular Contributor

Hi,

I'm just getting started with SPFx and development and was wondering if you had any pointers for me regarding the following:

 

In SPO, we require some sort of disclaimer pop-up overlay (not simple js alert) that appears as soon as a user visits a certain site collection.

 

Can something like this be achieved with SPFx? On https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/overview-extensions there's a note stating that there is a known bug with list and library extension support in the classic experiences.

 

Thanks for your help getting me started.

2 Replies
best response confirmed by Florian Hein (Regular Contributor)
Solution

It is possible - I've done something similar (a cookie consent popup) within our organisation which requires us to display a popup overlay in the middle of the screen, notifying our users about our End User Policy, there's a link within the popup as well which takes them to that policy page.

 

In the Classic site days, we had the code embedded within the Master Page, sadly that's not really an option with Modern Team Sites, so I refactored the code into an SPFx Web Part instead and what I did was to deploy it to all team sites via the App Catalog and the "skipFeatureDeployment" switch in the package file, which then made it easier for me to deploy it via PnP framework.

 

There are two dependencies in the cookieconsent JS and CSS files that need to be included (happy to send these to you) and I've included a chunk of the TS code as well.

 

I've not tested it, but you could set the cookieconsent part to 0 days (from the cookieconsent JS file) to ensure the popup comes up all the time I think. It might not be the best way to achieve your objective, but hopefully it's enough to get you started.

 

  public render(): void {
      require('./cookieconsent.min.js');
      require('./cookieconsent-min.css');

    this.domElement.innerHTML = `
      <div class="${ styles.enduserPolicy }">
        <div class="${ styles.container }">
          <div class="${ styles.row }">
            <div class="${ styles.column }">
              <span class="${ styles.title }">End User Policy</span>
              <p class="${ styles.subTitle }">REQUIRED - PLEASE DO NOT REMOVE</p>
            </div>
          </div>      
        </div> 
      </div>`;

      window.addEventListener("load", function(){
        window["cookieconsent"].initialise({
          "palette": {
            "popup": {
              "background": "#00728f",
              "text": "#ffffff"
            },
            "button": {
              "background": "transparent",
              "text": "#ffffff",
              "border": "#ffffff"
            }
          },
          "position": "bottom-left",
          "content": {
            "message": "Here's some text about policy stuff.",
            "dismiss": "Understood!",
            "link": "End User Policy",
            "href": "link here"
          }
        })})
  }

 

@Steve Johnson  that sounds really interesting! I need a pop-up on an entry-site ("I declare I don't do this and that..."). Can you send me (or post) the files you mentioned as well?