UIWebView crashed when link with target="_blank" selected - iphone

I am using UIWebView to display web pages in my application. but when hyperlink with target="_blank" is get selected application terminate automatically.
is there any way to avoid this crash.
Thanx in advance.

After researching, I found that if we set target of an a tag to _self we can avoid the crash easily. But still there is on restriction to this, as we can apply the Javascript in this method:
- (void)webViewDidFinishLoad:(UIWebView *)webView
So before, selecting this link before loading the page crashed the application as no Javascript is applied.
If anybody knows solution, guide to me.
Thanks

Related

How to apply local styles / JS to UIWebview after loading a URL

I am loading a web page in my iPhone app. However the page is not mobile optimized. So, I would like to customize some elements from the page like remove sidebar etc.
For doing this, I guess, some CSS / JS need to be injected into the page to modify the page. Can this be done ? If yes, how to?
Any help appreciated.
For others having same question:
It can be done by using stringByEvaluatingJavaScriptFromString: method of UIWebView (upon webViewDidFinishLoad)
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('topBarBody').remove();"];
}

iPhone UIWebView problem

I am trying to write an application to show a web page in a web view for this link:
http://just4u.safeway.com
But the page can not be shown in the UiWebView, I got a message:
This page contains the following
errors: error on line 90 at column 11:
AttValue: " or ' expected.
Can someone let me know what could be the problem? I already added code to handle redirect, but still get the same problem.
Thanks
Try explicitly setting the MIME type of the page to be "text/html". Otherwise it may be parsed in the UIWebview as xhtml. Also check that your <!DOCTYPE> is not claiming to be xhtml.
I was running into a very similar problem.
I was using the loadRequest method of UIWebView, which was causing the UIWebView to interpret it as XHTML.
I instead used NSURLConnection to asynchronously load the data for the webpage, then used
[webView loadData:downloadedData MIMEType:#"text/html" textEncodingName:#"UTF-8" baseURL:[NSURL URLWithString:pageURLString]];
and got the page to display without the pink error box at the top.
This is essentially the same solution as PengOne suggests - I just wanted to confirm that the suggestion works fine, and show the sample code that worked for me.

Using HTML pages in UIWebView, strange issues with relative page images but links work

So I'm creating an app which basically is a UIWebView that loads an HTML page, which should have images on it. The HTML page is loading fine (confirmed with a little text on the page), but then I have this code in it:
<img src="images/image_1.png">
test
Check this out:
The tag has a broken image link
But, when I tap on the link, the
image loads!
How is this happening? What kind of solution is there?
I have the images in a subfolder of resources, which I added by "Create Folder References."
Help? A note: This is on iPad, using 4.2. But that shouldn't matter, right Apple? (Also, changing it to xml <img /> type tag doesn't do anything)
The image was way too big - over 2500px wide. Resizing to 1024px fixed it. Thanks Jose Vega.
Also, Automator is a gift from the Gods when it comes to batch operations.

Editable UIWebView in iPhone

I have seen some write about making a UIWebView editable. I would like to be able to compose a message containing both text and images the WYSIWYG way, and I thought that I might do it with a UIWebView.
Is this a good solution and how do I do this? I have searched the web for examples, but found none.
Thank you
UIWebView content can be made editable starting with iOS 5.0+.
A very nice tutorial can be viewed here: http://ios-blog.co.uk/tutorials/rich-text-editing-a-simple-start-part-1/
The tutorial goes beyond the question, so here's a resume of how to make the UIWebView editable:
//index.html
<html>
<body>
<div id="content" contenteditable="true" style="font-family: Helvetica">This is out Rich Text Editing View </div>
</body>
</html>
//somewhere.m
NSBundle *bundle = [NSBundle mainBundle];
NSURL *indexFileURL = [bundle URLForResource:#"index" withExtension:#"html"];
[webView loadRequest:[NSURLRequest requestWithURL:indexFileURL]];
Anyway, I suggest reading the tutorial, since it shows how to do other stuff as well (changing fonts, colors, embedding images etc.)
You could use the loadHTML:baseURL method from the UIWebView class reference:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html
Place this in the textViewDidEndEditing: delegate method of the UITextView:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextView_Class/Reference/UITextView.html
Actually UIWebView way is so painful, mobile safari does not support WYSIWYG rich text editor area.
From Zoho FAQ :
I can't create or edit documents on my iPhone, the keyboard doesn't show up when opening iZoho on iPhone. What's the problem?
It is an issue with the iPhone as the safari browser doesn't seem to recognize the rich text editor area and hence the keyboard isn't appearing. This is not an iZoho specific problem as all the applications that use a WYSIWYG editor face the same issue. We hope that Apple will address this issue soon and come up with the next version of iPhone's Safari that supports rich text editing. As a workaround, we may give a plain text editor for users to edit/create their documents if this isn't corrected in Safari's next version.
You should implement rich text editing by yourself :(

Remove html tags from UIWebView

I am developing an application for iphone which needs to load some description to a UIWebView. But text that loads into the UIWebView shows some html tags like <p></p>.Is there any way to remove these type of tags?
Thanks in advance
I asked a similar question the other day and got some good responses. I imagine one of these could suit your needs.
anyway to delete all <a href=> tags with javascript after the page loads on an iPad?
Hope it is helpful!
This is the best answer and is exactly what you are looking for ...
Write the following script in the webView delegate method. ( UIWebviewdidfinishLoading)
NSString *myText = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.textContent"];