CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: JavaScript

Copy to Clipboard in JavaScript

432 Views
Copy Code Show/Hide Line Numbers
function copyToClipboard(e) {
    $('#CodeDisplay').editable();
    $('#_contenteditor')
     .focus()
     .select()
     .keydown(function(e) {
        // capture Ctl-C, Ctl-X, ESC to remove editable
        if (e.which == 99 || e.which == 120 || e.which == 27) {                
            // have to delay so text doesn't go away before copy operation
            setTimeout( function() { $("#CodeDisplay").editable("cleanup") },500);
        }
    });
 
    // show overlay message
    $("#divCopyDialog")
                .centerInClient({ container: $("#divContainerContent") })
                .css("top", 350)
                .shadow()
                .closable()
                .draggable()
                .show()
                .fadeIn(1000);
    setTimeout(function() { $("#divCopyDialog").fadeOut(1000); }, 3000);
};
by Rick Strahl
  December 17, 2009 @ 3:40pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate