views:

766

answers:

2

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?

A: 

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.

Louis Gerbarg
+1  A: 

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.