I'm developing a Backbone.js based web app that for some use cases will be wrapped inside a native iOS UIWebView. In the iOS app – when we want to change page in the web view – we simply initiate a new request on the web view, which loads the page accordingly.
My only problem is that when there is a Backbone route defined for the requested URL, I want the web view to use Backbone's routing and pushState
instead of initiating a whole new page load. However, when there isn't any Backbone route corresponding to the requested URL, the web view should handle it as a whole new page request and "reload" the page with that URL.
Right now the native app uses UIWebView
's loadRequest:
method and passes a new NSURLRequest
, with a URL of e.g. "http://example.com/search", as parameter.
Right now my only idea is to use UIWebView
's stringByEvaluatingJavaScriptFromString:
method:
- Have the web view call some JS function that in turn will check if my Backbone routes can handle that URL.
- If yes, it should trigger the router callback.
- If not, it should initiate a new page request with the URL.
Any input? Is there any built in way of solving this?
Thanks!