Autocorrect not working in UIWebView - iphone

In my app I am displaying a URL on my UIWebView .This webView page also consist textfields and I want to disable the autocorrect function = off for these textfields. I have tried all the methods but all in vain.
Here is my code
[webView stringByEvaluatingJavaScriptFromString: #"var field = document.getElementsByTagName('input');"
"for(var i = 0 ;i < field.length;i++){ "
"if(field[i].type == 'text'){"
"field[i].autocorrect = 'off';"
"field[i].spellcheck='off';"
"field[i].autocomplete='off';"
"field[i].value = 'hello';"
"}"
"}"];
As you can see i tried all these function (autocorrect, autocomplete and spellcheck as off) both individually and as a combination. But nothing works.

What I discover that if you are fetching an HTML page (and that you don't have access to its HTML source code) and you are trying to access it as above method then all will work fine like "textfield.value", "textfield.type" etc. but the "textfield.autocorrect = 'on' " (or off) does not work.
Because on clicking textfield of HTML page the keyboard of iPhone comes and you cant take object of HTML textfield to Objective C textfield. Hence the two options to solve this are:
Either make autocorrection as off from iPhone "Setting" menu .
Or ask who have access to this HTML page source code to put autocorrect="off" in between textfield HTML code (i.e. .html file)

Related

Pinch To Zoom in UIWebView in iphone App

I am Developing simple App. I am accessing html pages on UIWebVIew. and I wanted to zoom that html pages with the help of zoom option
please help me out.
Zooming IN, OUT and Pinch are Built In feature of UIWebView. You don't need to write any code to achieve that.
Simply , Use your fingers.
On Simulator , you can use Option (Alt) and Shift Keys with Mouse.
Make your option Scale Page to Fit ON.
Try this below property
webView.scalesPageToFit = YES;
First of all set this property given below:
webView.scalesPageToFit = YES;
Then you have to set view port on meta data on the html string. In my case head tag was empty. Thats why I just replaced head with the with head containing meta tag.
htmlString = [htmlString stringByReplacingOccurrencesOfString:#"<head></head>"
withString:#"<head><meta name=\"viewport\" content=\"width=568\"/></head>"];
[webView loadHTMLString:htmlString baseURL:nil];
Using Storyboard :
There is built-in property of WebView ‘Scales Page To Fit’ which is false by default.
Select WebView -> Open Utilities Window -> Goto Attribute Inspector’
Set ‘Scales Page To Fit’ to true (Checkmark it)
Programmatically :
objWebView.scalesPageToFit = true

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.
Someone suggested to me the selecteddomrange function of the WebKit framework, but it works with Mac OS, and I need it in 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?
You can use UIWebViews
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
and get the innerHTML element property via a JS expression.
Have a look at the JS function 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.
Have a look at the DOM Range Spec

No response after submitting form on iPad from UIWebView

I am currently opening a webpage in UIWebView and submitting a form which performs a query on the server side and youtube video is returned (if available). I have no say/control over the server side implementation.
This webview works fine on iPhone/iPod, however, when I try to run the same app on iPad there is no response after submitting the form.
I created a dummy app, compiled on iOS 3.2 and problem is still there.
I put NSLogs in webview delegate methods which shows that after the form is submitted (UIWebViewNavigationTypeFormSubmitted) nothing happens.
I'm unable to figure out why this happens only on iPad and not on iPhone/iPod Touch.
I have created the webview in IB and setting the URL is viewDidLoad
[viewTourWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.realestatetour.com/mobiletours.htm"]]];
The URL for reference is http://www.realestatetour.com/mobiletours.htm
Enter the Tour ID as 10.
Thanks
The reason it wasn't working is because the form opens the result in a new page, (i.e. _blank) and apparantly all links opening in new window are ignored by uiwebview and its delegates.
I found 2 possible solutions for this:
1) Modifying the html using javascript to replace all _blank with _self for all anchor tags.
(source)
2) A more elegant solution which works for handling links which open a new window.
(source)
In my case i recreated the web page displaying form on the iphone app and changed _blank to _self.

UIWebview contents as NSString from HTML

I'm trying to reading part of HTML source code from website that has been encapsulated by javascript;basically i'm trying to read email which appears in webview but not in real source code using NSString method of 'NSString stringWithContentsOfURL:(NSURL *)url'. it looks like code showing up before hitting up the inner java script (which executes and shows the email address to show).
are there any way i can get into NSString the contents that I viewed over UIWebview?
I tried to use the method 'webView stringByEvaluatingJavaScriptFromString' it worked for only displaying through webview browser didn't return any string value.
Are there anyway I can get the string?
This should work in the general case:
NSString *markup = [webView stringByEvaluatingJavaScriptFromString:
#"document.getElementsByTagName('html')[0].outerHTML"];
Just make sure the page is loaded before you call it.

How do I know if text contains URL links (UIWebView)

I have some text which might or might not contain web URLs, phone numbers, email links etc. which UIWebView automatically detects as hotspots.
Question: I want to show this text in UIWebView ONLY when there are one or more hotspots, but as plain text if it doesn't. So how can I detect this in code?
Additional Info: JavaScript code below tells how many ... links there are. This does NOT count how many other "link" items there are. For example "Link to www.yle.fi" contains one link according to UIWebView, but zero according to JavaScript:
NSString *s = [webView stringByEvaluatingJavaScriptFromString:
#"document.links.length"];
Still no answer to the question how to ask UIWebView how many links it has found...
You can use several regular expressions and check if the text matches those of URL/phone number/email addresses.
However, if your intention is simply let the user open a link, the UITextView is suffice.
Check the dataDetectorTypes property.