There is an <img id=...> . It is necessary to put the base tools js id of this image in the buffer by ctrl+click . This is real? If so, how?

On the basis of the received answer, I made the following universal function:

 function Copy(event, value){ if (event.ctrlKey){ var copy_buffer = document.createElement('div'); copy_buffer.textContent = value; copy_buffer.style.position = 'absolute'; copy_buffer.style.left = '-1000px'; copy_buffer.style.top = '-1000px'; document.body.appendChild(copy_buffer); var range = document.createRange(); range.selectNodeContents(copy_buffer); var selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); document.execCommand('copy'); document.body.removeChild(copy_buffer); } } <img onclick="Copy(event, this.name);" ... 

Thanks again for the tip!

    1 answer 1

    http://caniuse.com/#feat=clipboard

     document.getElementById("smth").addEventListener("click", function (event) { var cp = document.getElementById("cp"); cp.textContent = event.target.id; var range = document.createRange(); range.selectNodeContents(cp); var selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); document.execCommand('copy'); }) 
     #cp { position: absolute; left: -1000px; top: -1000px; } 
     <img id="smth" src="//www.gravatar.com/avatar/cbfaff96665b7567defe1b34a883db8b?s=128&d=identicon&r=PG" /> <div id="cp"></div> 

    • The idea is clear. Thank! - Iceman