Search code examples
javascriptsharepointclipboard

Copy SharePoint listcolumn to clipboard using Javascript


I am looking for a way to copy 5the content of a SharePoint list column into the clipboard by just pressing a button. I know I can select the content and do a right click, but I want it a bit more convenient. Any help or hint would be appreciated.


Solution

  • If you open up your console in your browser (F12) you will have to find the "ID" of the element which content you want to copy to your clipboard.

    Most browsers restrict copying anything to your clipboard however the function below shows a prompt containing the content you want to copy. Just press ctrl+c and you are good to go!

    function copyToClipboard(text) { window.prompt("Copy to clipboard: Ctrl+C, Enter", text); }

    For example:

    copyToClipboard(document.getElementById('demo').innerHTML)

    If you want to retrieve the contents of a specific column of every row in a SP list. You will have to write some kind of loop which loops through every element and retrieves the content of the in your case 5th column and store it in array.