Detect if UIWebView is showing www.example.com link - iphone

How can I do an if statement to check if UIWebView is displaying a certain page or not?
Thanks,
James

currentURL = webView.request.URL.absoluteString;
NSLog(#"%#",([currentURL isEqualToString:desiredURL] ? #"YES" : #"NO")];

You could try using the url property of the request - see SO for an example
But I'm not sure how you could handle different encodings of the same URL or IP addresses instead of FQDN's.

Related

UIWebView Default no connection Page

Sorry for asking this silly question.
How can we load default safari page when not connected to the internet, like the page below, in our application?
Thanks in advance
Chahal
First check for an active Internet Connection here, then load local html file into the uiwebview here.
Did you mean : open a default page in the Safari application when taping on some button inside your application?
If yes, then here is the code :
[[UIApplication sharedApplication] openURL:[YOUR_URL_HERE]]

Load internet links from HTML string

I am using the function (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
[webView loadHTMLString:sourceCode baseURL:nil];
to load some source-code I wrote, with links to internet content. For instance :
Google
The string load well, but there is no way to access the google link then.
Do you know what I am doing wrong ? Is there anything to do with the baseURL ?
your webpage must return a string that just contain http://www.google.com. If you need to use the link, you must modify the NSString that you receive to extract the right url!
Try setting the dataDetectorType for your webview like this:
webView.dataDetectorTypes = UIDataDetectorTypeLink;
Hope this helps!

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.

how to place url string

hi i am new to iphone. what i need is i have to place a url as a string eg:http://stackoverflow.com by selecting the string it self open in a web brosewr how can i done this. post some code or link thank u.
Add a textView control onto your NIB file. Put whatever content (you mention 5 lines of text) you want in here. In the properties for this control, under the "Detection" section, click "Links". Then, any URL links in this text will be automatically highlighted in blue, and when your users tap on it they will be taken to that URL in the browser.
Your question could have been a little clearer - I only got what you were after because of your previous comment on puckipedia's answer...
To open A url use (in Objective-C)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URLHere]];

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.