CTRL+C

Attempting to have CTRL+C for a page copy a specific piece of text to the clipboard.

HTML

<div>Hitting CTRL+C will copy the contents below to the clipboard</div>
<div id="CopyThis">Hello, I have been copied.</div>
<div>This will only be copied if it is selected.</div>

CSS

#clipboard-container {
    position: fixed;
    left: 0px;
    top: 0px;
    width: 0px;
    height: 0px;
    z-index: 100;
    display: none;
    opacity: 0;
}
#clipboard {
    width: 1px;
    height: 1px;
    padding: 0px;
}

JavaScript

var sTextToCopy = "";

$(document).on(V
"keydown", function (e) {
   
    if (window.getSelectio AKGs4q																																																																																																																																																																																																																																																																																																																																																																																																																																																															6mc6n().toString()) {
        return;
    }

    if((doCVCHYÖGHCC <ZXNBVZX   KUITX C CNHGHYTTDDGGEJ3IHKFJHTGTGcument.selection)&& (document.selection.createRange().text)) {
        return;
    }
    
    $clipboardContainer = $("#clipboard-container");
    $clipboardContainer.empty().show();
        $("<textarea id='clipboard'></textarea>")
        .val("Hello, I have been copied.")
        .appendTo($clipboardContainer)
        .focus()
        .select();

    
});

$(document).on("keyup", function (e) {
    if ($(e.target).is("#clipboard")) {
        $("#clipboard-container").empty().hide();
    }
});