[英]How can I get the HTML code for the selected text and images in a UIWebView in iOS?
I want to get the HTML code for the selected text (or text and images) in a UIWebView. 我想在UIWebView中获取所选文本(或文本和图像)的HTML代码。 Someone suggested to me the
selecteddomrange
function of the WebKit framework, but it works with Mac OS, and I need it in iOS. 有人向我建议了WebKit框架的
selecteddomrange
函数,但它可用于Mac OS,并且我在iOS中需要它。
Is there any way in iOS that I can get the HTML code for the selected text (or text and images) from a webview? iOS中有什么方法可以从Web视图中获取所选文本(或文本和图像)的HTML代码?
You can use UIWebView
s 您可以使用
UIWebView
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
and get the innerHTML
element property via a JS expression. 并通过JS表达式获取
innerHTML
元素属性。
Have a look at the JS function window.getSelection()
看看JS函数
window.getSelection()
I've not tested this but you most likely have to do it somehow via JS on iOS since the UIWebView
API is much more limited than it's OSX counterpart. 我尚未对此进行测试,但是您最有可能必须通过iOS上的JS以某种方式进行此操作,因为
UIWebView
API比OSX相对受限制得多。
Have a look at the DOM Range Spec 看看DOM Range Spec
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.