for clipboard this is working
const str = "Text" const withClipboardPolyfill = (obj, prop, cond, copyFnIfCond)=>{ const copyToClipboard = () => { if(cond()){ copyFnIfCond() } else { const textarea = document.createElement('textarea') textarea.value = str textarea.style.visibility = 'hidden' document.body.appendChild(textarea) textarea.select() document.execCommand('copy') document.body.removeChild(textarea) } } obj[prop] = copyToClipboard return obj } const api = (function() { const o = { copyToClipboard(){ return navigator.clipboard.writeText(str) } } return o })() let copyBtn = document.createElement('button') copyBtn.id = 'copy-to-clipboard' document.body.appendChild(copyBtn) copyBtn.onclick = api.copyToClipboard() copyBtn = withClipboardPolyfill( copyBtn, 'onclick', ()=> 'clipboard' in navigator, api.copyToClipboard ) copyBtn.click()
The example shown here, I am not sure.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
for clipboard this is working
The example shown here, I am not sure.