UIWebView - How to import only text from website? - ios

My question is: Can UIWebView import from website only plain text? Without any formatting etc? Or mayby there is another simple way to import just simple text from website into an iOS app?
Thanks for help!

It shouldn't be done with UIWebView.
Use an Http Connection to get page content then strip the HTML tags.
nsurlConnection
Stripping
or, in the did finish loading get html and strip it then reset the webview content
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[myUIWebView loadHTMLString:strripedString baseURL:nil];
}

Related

Unable to get HTML string from UIWebView

I loaded a file on uiWebView. Its extension type is ".pages". Now I trying to get HTML string from webview, but it returns to empty string.
For ".doc or .docx" files getting the String. It happens to ".pages" extension only.
Thanks in Advance,
NSString *html = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.outerHTML"];
Refer this post - Reading HTML content from a UIWebView

Detect when url containing local anchor tag is clicked on UIWebView?

I want to detect when a url with local anchor tag is clicked on html page which is current been rendered on UIWebView. I have done lots of searches around and implemented various workarounds but no success. The ultimate suggestion from all around always comes to this delegate method
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
The biggest problem what I concluded was that this method simply doesn't get called for local anchor tags if already in a rendered HTML page. What i mean is if fresh new page URL (anchor tag) included is clicked that method gets fired. Here is an example. If i my UIWebView has already rendered www.xyz.com, now if i press some url which is like www.xyz.com#amazing (link present on that same page) then delegate method doesn't get fired.
I was developing a simple in-app browser. I had to show URL of every page been rendered/visible at address box of my in-app browser. Only obstacle now is i cannot show every anchor tags/javascript links that just brings new content but same URL domain.
There were solutions regarding usage of this
`[webView stringByEvaluatingJavaScriptFromString:#"window.location.hash"]`
Problem is that until and unless if I can't get delegate method called/fired than there is no benefit of this code.
Is there any workaround or shall I just give up on this? I hope I am clear with explaining the problem.
Note: Best TestCase Scenario is mobile version pinterest.com on UIWebView
Thanks.
I don't exactly follow what you're trying to do, perhaps you could clarify a bit more.
In the meantime, here's how to get your UIWebView to handle every link click in the web page it has loaded. It's looking for a URL Scheme that begins with "bloodwing". If it finds it, it will stop the request. Otherwise, it will work as expected.
So http://www.yahoo.com will work, and bloodwing://www.yahoo.com will fail.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
if ([url.scheme isEqualToString: #"bloodwing"]) {
[webView stringByEvaluatingJavaScriptFromString: #"doSomething();"];
return NO;
} else {
return YES; // Return YES to make sure regular navigation works as expected.
}
}
Hopefully this helps!

iOS RSS feed data fetching : How to get Description / Content of feed

I have followed this tutorial http://www.raywenderlich.com/2636/how-to-make-a-simple-rss-reader-iphone-app-tutorial#comments
But I also want to get description/content instead of showing its URL in web view.
I tried everything but nothing worked.
Any help?
As shown in ray wenderlich website, you can get the feed details from GDataXML's GDataXMLElement. Check the key you are getting for description/content GDataXMLElement like:
[item valueForChild:#"description"]
and save that string in the nsobject class you created to save the rss feed required data. After that you can load html string in the webview and add your custom css styling for the html string if needed. You can load html string in webview using webview's
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
method. Hope my answer helps.

How to get the HTML page after executing java Script

I am using
[webView stringByEvaluatingJavaScriptFromString:#"validate(x);"]
to execute a java script function and I am getting return value that is returned by "validate(x)"
but i want HTML page (response, ie WEB page) that will be displayed after executing java script function.
Is there any way to do so in objective C programming?
You could try calling
NSString *htmlContents = [webView stringByEvaluatingJavaScriptFromString: #"document.body.innerHTML"];
Some time after
[webView stringByEvaluatingJavaScriptFromString:#"validate(x)"];
Maybe you could process UIWebView delegate's methods from UIWebViewDelegate when it finishes loading the page,
- (void) webViewDidFinishLoad:(UIWebView *)webView
but I'm not sure if it will work with your JS.

iOS UIWebView - refresh only part of html file

Is there any way to refresh only part of an HTML file displayed in a UIWebView? For example, if I make changes to a div in the body, is there any way to refresh only the contents of that div tag? Or do I have to reload the entire file into my UIWebView?
You have to reload entire HTML file. It is not possible to reload only part of pure HTML file.
Using a little bit of javascript?
use javascript like this
NSString *js = [NSString stringWithFormat:#"document.getElementById('foo').innerHTML ='update';"];
NSString *res = [self stringByEvaluatingJavaScriptFromString:js];

Resources