0

I was wondering if it's possible to auto insert text into a site collection sharing dialog window when a user clicks to share the site collection.

enter image description here

I have very basic JavaScript knowledge. I fiddled are a bit and got the part working where the desired text is pasted into the dialog box - at least in the Chrome dev tools.

let id = document.getElementById("TxtEmailBody");
let pasteText = document.createTextNode("Disclaimer");

id.appendChild(pasteText);

Unfortunately, this code only works when the sharing dialog is already open. How can I achieve it so that this code runs when the dialog is being opened?

I'm looking for a vanilla JavaScript solution.

Thanks!

1 Answer 1

1

There is no "vanilla" way to do it, but one way would be to put it inside JavaScript setInterval to wait for the dialog to appear. I'm not that fluent in pure JavaScript, so allow me to include some pseudo-code.

setInterval(function() {     
    if(!(dialog is visible)) {
        return;
    }

    let id = document.getElementById("TxtEmailBody");
    let pasteText = document.createTextNode("Disclaimer");

    if(id element does not equal to pasteText) {
        id.appendChild(pasteText);
    }    
}, 1000);

You could then include this JavaScript to whole site collection as UCA (User Custom Action), e.g., using Chrome Extension: SPEditor (SharePoint Editor) (called Scriptlink in the extension).

Please note that UCAs don't work on modern pages, so if you're using those, you need to use some other way to load this JavaScript on those pages, e.g., by using SPFx Extensions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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