Copy To Clipboard Safari
Is it possible to copy the text from text area to clipboard in Safari (HTML), if yes then how, or if not, is there any alternate?
iMac, OS X Mavericks (10.9.4)
You can make a difference in the Apple Support Community!
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
Is it possible to copy the text from text area to clipboard in Safari (HTML), if yes then how, or if not, is there any alternate?
iMac, OS X Mavericks (10.9.4)
Thanks for replying.
Let me explain about this scenario. I have a textarea with some text inside it and also I have button called "Select & Copy" which selects the text however doesn't copy the text into the clipboard.
Thanks again for the response 🙂
Here is my Code:
function CopyToClipboard () {
var input = document.getElementById ("text_area");
var textToCb = input.value;
var flag = true;
if (window.clipboardData) {
window.clipboardData.setData ("Text", textToCb);
}
else {
var forExecElement = CreateEelementCmd (textToCb);
SelectContent (forExecElement);
var supported = true;
try {
if (window.netscape && netscape.security) {
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect"); }
flag = document.execCommand ("copy", false, null); }
catch (e) {
flag = false;
}
document.body.removeChild (forExecElement); }
if (flag)
{
alert ("The text is already in the clipboard");
}
else {
alert ("Your browser doesn't allow clipboard access!");
}
function CreateElementCmd (textToCb)
{
var ExecElement = document.createElement ("div");
ExecElement.style.position = "absolute";
ExecElement.textContent = textToCb;
document.body.appendChild (ExecElement);
ExecElement.contentEditable = true;
return ExecElement;
}
I hope it helps. In the above code, I am getting only the second alert i.e "Your browser doesn't allow clipboard access!". I have tried with all possible browsers but no luck.
This is highly unhelpful. Where do you get 3 years? Using clipboardData is an HTML5 feature which is NOT an outdated approach. In fact it is still considered bleeding edge so there is not much information about caveats and how to overcome them. Browsers are still working to support this feature, as can be seen here:
I am trying to get a copy event dispatched in Safari as well (I have it working in FF and Chrome).
I cannot seem to capture the copy/oncopy event in Safari.
I will reply again if I get it working. Best of luck and let me know what you figure out.
You can drag over an area to highlight and copy as plain text to the clipboard.
Then your page code has some errors and I can't fix that.
Tell your visitors how to press the c and control (PC) or command (Mac).
Do a Google search and you'll find your code is 3 years out of date and would only work with ancient browsers.
Try some other method.
I also use document.execCommand('copy') in IOS safari
From my test. IOS8.0 Safari can copy as well, but IOS7,9 or other IOS8 version can't!
If you have any solutions, please let me know. thks~
Copy To Clipboard Safari