Fir*_*fly 2 iphone objective-c uiwebview ipad ios
我似乎无法将execCommand用于剪切,复制,粘贴以在contentEditable设置为true的UIWebView中工作.我可以使用selectAll命令选择文本,但剪切,复制和粘贴不起作用.
这是我正在使用的代码:
[webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('cut', false, null)"];
Run Code Online (Sandbox Code Playgroud)
还有什么我需要做的才能让剪贴板操作起作用吗?
按照之前的评论剪切,复制,粘贴命令似乎不起作用,所以我设法实现了相同的操作:
- (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 = @"";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2406 次 |
| 最近记录: |