UIWebView execCommand剪切,复制,粘贴 [英] UIWebView execCommand Cut, Copy, Paste
本文介绍了UIWebView execCommand剪切,复制,粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法将execCommand用于剪切,复制,粘贴以在contentEditable设置为true的UIWebView中工作。我可以使用selectAll命令选择文本,但剪切,复制和粘贴不起作用。
I can't seem to get the execCommand for cut, copy, paste to work in a UIWebView that has contentEditable set to true. I am able to select the text using selectAll command but cut, copy, and paste do not work.
这是我正在使用的代码:
This is the code I'm using:
[webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('cut', false, null)"];
我还需要做些什么才能让剪贴板操作正常工作吗?
Is there something else I need to do to allow clipboard operations to work?
推荐答案
按照之前的评论剪切,复制,粘贴命令似乎不起作用,所以我设法实现了相同的操作:
As per previous comments cut, copy, paste commands don't appear to work so I managed to achieve the same operations like so:
- (void)cut
{
NSString *selection = [self.webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
[webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('delete', false, null)"];
[UIPasteboard generalPasteboard].string = selection;
}
- (void)paste
{
NSString *text = [UIPasteboard generalPasteboard].string;
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.execCommand('insertHTML', false, '%@')", text]];
[UIPasteboard generalPasteboard].string = @"";
}
这篇关于UIWebView execCommand剪切,复制,粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文