UIWebView - how to get visited links to display as visited? - iphone

I have a UIWebView in my iPhone app, which merrily shows web content, but it does not render visited links any differently to unvisited links. Ordinarily I'd expect it to use a different colour for visited links, but alas no.
Safari on the other hand deals with its links correctly. I assume that UIWebView is lacking a store of information about what URLs it has visited. It's reasonable to expect the delegate to supply this information, but there is no such API on the delegate, or anywhere else that I can see.
So, how can I get UIWebView to show visited links as visited?

I came to the conclusion that the only way to get this functionality is to fake it.
I got this working successfully by adding a JavaScript function to all the pages to apply a "visited" class to all links whose target is on a list that I pass in from Objective-C (with UIWebView's stringByEvaluatingJavaScriptFromString: method). Then I just have to maintain that list in the Objective-C world and always fire off that JS function in the web view delegate's webViewDidFinishLoad: method. The hardest bit was the JavaScript.

Aside from changing CSS properties in javascript by call stringByEvaluatingJavaScriptFromString: there is probably no supported way to do it in the official SDK. UIWebView is very limited compared to WebView on the desktop.

Related

Best way to hide content from UIWebview?

I have a UIWebView into a mobile website that I run, and would like to hide some links when it's seen by the WebView--but not mobile Safari. It seems like there's several approaches to this:
Evaluate custom Javascript to hide elements of a certain class.
Pass in a GET parameter so that the server does it.
Pass in a custom header so that the server does it.
Maybe something else...
To me it seems like they all have their tradeoffs. What's the best way of doing it?
If you want to do this, I'd say detecting the UA with JavaScript is probably the way to go because it will be added automatically, and you can concentrate on the website, rather than having to add code to both.
Also, you don't have to check every time a link is clicked to add a custom header or GET parameter.
What I do to make the distinction between UIWebview and mobile Safari is using the userAgent (a custom one for the webView). Based on the UserAgent I display different content for each "platform"

Embeddinig another website into a GWT application

I'm building a GWT application that looks great. At the end of the page I'd like to include a WordPress blog that I'm developing. In order to do that I want to use a com.google.gwt.user.client.ui.Frame so that an IFrame gets created, and the Wordpress just gets seamlessly embedded.
I've built this and it seems to work, although there's a problem with the size of the IFrame. I'm not sure how it's getting sized, but it's too small so that scrollbars are thrown onto it. This makes the the embedding not so seamless.
What should I be doing so that this second webiste can be seamlessly embedded into my GWT app?
The easiest solution is to make iframe as big as possible, and hope that there will be no unexpected scrollbars.
Also there is another way, if you have access to the innerDocument of iframe (if SOP doesn't stop you from doing this), you can compare its size against the size of iframe, and increase iframe height/width if necessary.
If blog is in another domain, you might try to use cross-document messaging to retrieve information about the size of document(this will not work in IE7,IE6 and you will have to put some additional JS on your blog).
Also you can include information from your blog without using iframes. You can simply pull RSS of your blog, parse it and display it in any way you like it.

Cross-domain navigation within Blogger without Javascript

The setup: I have a Blogger blog set up on a domain name as blog.mydomain.com. The main site site at mydomain.com is running Umbraco CMS.
The problem: I need to have the navigation from the CMS transported to Blogger somehow, so that making a change on the main website doesn't require the extra step of modifying the navigation inside Blogger.
Generating the navigation data on the CMS side in what ever format it needs to be (XML, unordered list, JSON, etc) is not a problem. The problem is getting the data from Umbraco to Blogger after it is generated.
I'm not yet willing to use Javascript, as this would seriously impair the website for users browsing without Javascript. (Too bad because AJAX would be a very workable solution.)
I've tossed around the idea of using an iFrame. How would this work for a navigation system including sub-menus? Creating and deleting multiple iframes is out of the picture, since I don't want to use Javascript. I could use one large iframe to allow for the sub-menus, but then it would cover content at the top of the content area, rendering it unclickable.
I'm thinking about how you could do this, but while I do - in this day-and-age javascript has become very common. Most users are going to have it, and those with it disabled really shouldn't be on the web. Is this the only reason you don't want to use javascript? Around 2% according to YDN have js disabled, and that's lower from other countries. As time goes on that 2% should get lower, I don't see that as an issue. However if you absolutely can't use javascript, I'll keep thinking. I might have an idea, I'll need to test it though.
It's not possible to use IFrame, cause of same origin policy. Both sites are on different domains, when user click menu item inside IFrame, there is no way to call parent window.
There are few ways how this can be done.
1) Javascript solution. Use json rpc, or another cross-domain calls. Load menu from your CMS and render it. Yes, this requires javsascript, but, seriously, show me the site, which does not use javascript.
2) Direct server communication.
Is it possible to perform http call from blogger ? If so, just perform http call to your CMS from Blogger, get data and render it.
3) Mixed flash/javascript solution. Flash can perform http call regardless of same origin policy. Get data with flash, use ExternalInterface to call Javascript function to render data.
There is no another way to do it. I suggest you to use javascript solution
You could build an HTML skeleton of empty ULs in Blogger (the max that you might need) to hold your navigation contents, and then link to an Umbraco-generated external stylesheet.
This stylesheet could fill those LIs with CSS generated content using the :before and :after pseudo-elements, and hiding unused LIs with CSS display: none.
An example of this is at: http://jsfiddle.net/5bXja/1/
This works in IE8+ so depending on your clients, this may-or-may-not be more widely supported than Javascript. Likely not. ;-)

Accessing UIWebView contents from UI Automation in Instruments

I have a UIWebView in my application which has links inside that when clicked cause different actions to be carried out in the application. I'd like to be able to test this with automated testing so it can be added to a continuous integration build. However, the documentation is rather sparse for UIAWebView and I've tried to no avail to get this to work.
Has anyone had any success interacting with links inside a UIWebView so you can check that their action is correct?
Couldn't find a way to iterate/access links in a UIWebView but would this work for you? Access the page source with:
NSString *source = [webView stringByEvaluatingJavaScriptFromString:#"document.getElementsByTagName('html')[0].outerHTML"];
then look for the tags that you consider to be links (e.g. href=...)
Then you still need to be able to "press" those links. Is it enough that you navigate to the url given in the link? If so, just use loadRequest to do so. If you need more advanced behaviour (for example make sure correct javascripts are run), you'll need to do more magic to parse those and execute them with stringByEvaluatingJavaScriptFromString.

How do I implement a Floodlight tag into an iPhone app?

A client is asking me to insert a Floodlight tag into an Objective-C programmed iPhone app that is ready for submission to the App Store.
I did some Googling, and couldn't find anything about how to do this (it seems like you can you only add Floodlight tags via Javascript, but I'm not too sure). Can you do this, and, if so, how?
If nothing else, you can create an offscreen UIWebView and invoke the appropriate javascript with stringByEvaluatingJavaScriptFromString. Not a good solution, but if javascript is required it may be your only choice.
Instead of embedding a UIWebView right off the bat for this, you could try using NSURLConnection to request the URL normally inserted with the Floodlight iframe. It seems that unless the contents of the iframe (which should just be a transparent GIF) need to interact with the host page, simply performing and receiving the request should fulfill the purposes of tracking. Check the ToS, though, to see if they have any stipulations about this.