We apologize for the interruption. However, seabreezecomputers.com has been offering free tools and downloads for many years. Unfortunately, server expenses are now starting to exceed revenue earned. If you appreciate the free tools and downloads at seabreezcomputers.com please consider making a donation.
|
Here is a Copy to Clipboard Crossbrowser Javascript function that works for Desktop and Mobile browsers. Features
Paste Features
Demonstration Here is a form textarea to test copying of form data with: Here is a non-form element (a div) to test copying with: Here is a textarea you can test pasting into: Here is a contentEditable div to test pasting into: dlc_b Download Downloaded 0 times.
Please make a donation to reveal the download link.
How to Use First create your html form or non-form elements and give them an id.
Example: Next put this line in your html file after all your copyable elements: Then you can use the copy and paste functions in a few ways:
History 8/2/2019 - Version 1.2c - It seems that some iOS 12 devices are defaulting to "Request Desktop Site" (Desktop mode). In Desktop mode the useragent no longer has "iphone" in it and copy is not working in textareas. Therefore the code has been updated to no longer detect "iphone" in the useragent but instead to apply el.setSelectionRange(0, 999999); in every browser. This seems to fix the problem in iOS 12. Also changed readOnly to true to prevent iOS from displaying the keyboard when copying from a textarea. However, it still displays the keyboard when copying from a contentEditable element. 3/5/2018 - Version 1.2b - Bug Fix: Previously the tooltip opacity would make the tooltip not appear when it was done displaying. Even though the tooltip was invisible it would get in the way of a user trying to use the mouse to highlight some text in the textarea or to click in the textarea. Fixed by changing the display of the tooltip to none. Also changed the zIndex of the tooltip to be in front of other elements. 3/5/2018 - Version 1.2a - Added tabindex=0 to "Copy to Clipboard" button created by the function make_copy_button() for accessibility. 3/4/2018 - Version 1.2 - Added role="button" to "Copy to Clipboard" button created by the function make_copy_button() for accessibility. 4/14/2016 - Version 1.1 - Bug Fix: Form elements were limited to selecting 9999 characters because of an iOS limitation. Fixed on lines 75-76 and 134-135 by detecting if iOS and device and increasing the character selection on iOS devices to 999999. The bug originally has to do with an iOS limitation of only being able to select characters in form elements using el.setSelectionRange(); 3/18/2016 - Version 1.0 - Cool Javascript Copy to Clipboard Crossbrowser created Last updated on May 17, 2024 |
|
User Comments
|