开发者

UIWebView select all text to share on facebook

开发者 https://www.devze.com 2023-03-28 00:22 出处:网络
I have exhaustively searched for a solution with no success.... I have a UIWebView which ultimately I would like to share on facebook.I am using the facebook dialog api and, since the text is greater

I have exhaustively searched for a solution with no success....

I have a UIWebView which ultimately I would like to share on facebook. I am using the facebook dialog api and, since the text is greater than 1000 characters, I would like to post a link with a 'preview' description (e.g. the first 500 chars or so).

The problem I am having is getting the text from the UIWebView in a reasonable format. Ideally, it would format as if I used the win开发者_Python百科dow.getSelection() route. I can't figure out how to mimic this without the user actually selecting the text. If I could 'select all' and then trim the resultant string, that would be ideal.

As an alternative, I tried to use the textContent of the document (e.g.

NSString *myText = [self.webView stringByEvaluatingJavaScriptFromString:
                                          @"document.body.textContent"];

but this removes ALL formatting including any new lines...which causes all of the text to kind of run together.

Does anyone have any ideas on how to best accomplish this? I would so incredibly grateful!!!


Try to use jQuery text() function. http://api.jquery.com/text/
It seems to work for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号