VGTech is a blog where the developers and devops of Norways most visited website share code and tricks of the trade… Read more



Are you brilliant? We're hiring. Read more
the

iOS

category

Dissecting Javascript clicks in UIWebView

iOS

In VG we make heavy use of UIWebView, almost all of our iOS apps is a mix between native code and HTML. This is nice and dandy for presenting all sorts of content – being a newspaper means tons of webpages with ads, frames, javascript menus and whatnot.

Generally this works out really well, but for a long time we had a problem with links intercepted by javascript and how to distinguish these from an iframe loading. Why would we want to do this? Sometimes we wish to load linked pages in a separate view, leaving the originating page intact. Clicking on an article on our front page will push a new webview on the navigation stack so that when you’re done reading the article you can close it and instantly go back to the same spot on the front page. We use webview’s shouldStartLoadWithRequest delegate method for this purpose, like this:
(more…)