I created a button on the display form to copy a code to the clipboard. I copied the value to a text field first and have the following code int he button click. The alert shows the correct text but it will not write to the clipboard. I am using Microsoft Edge browser since that is the browser of choice for our organization.
var copyText = $(fd.field('Text1').$el).find('input')[0];
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
setTimeout(function(){
var copyText = $(fd.field('Text1').$el).find('input')[0];
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /*For mobile devices*/
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
alert("Copied the text: " + copyText.value);
}, 500);
Well using your questions I did have it hidden...so I simply unhid on button click then copied then re-hid it away which put it into the clipboard. Odd but it works.