Copying to the clipboard can be done in modern browsers with JavaScript's document.execCommand('copy', ...) which will copy the current selection. I'm not sure the way to feature detect support.
Essentially when a user clicks the button we need to highlight the code snippet and then copy it.