Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 6 multiple UIWebViews: Javascript only runs in one

An iOS 6 iPad app shows content in two UIWebViews. If both web views contain a jquery image rotator, only one will work at a time. Running < iOS 6, both work properly.

If the content of the non-animating webview is reloaded, it begins to work, and the other stops. Also, in the simulator ONLY, I can sometimes cause the stopped web view to start (and the other to stop) by clicking/dragging in it.

If one of the web views does NOT have javascript in it, the reloading of the stopped web view does not stop the functioning of the other.

My first thought was this was a focus issue, but the last bit seems to disprove that, and point so some kind of pollution between the two web views. The two rotators have the same selectors and same js scripts, but the js files are cached locally and are renamed uniquely to eliminate any stepping-on during the caching process.

I can't find anything in the iOS 6 release notes to describe a change in focus between different UIWebViews.

The web views are in an XIB, but but not siblings of the same parent UIView.

The desired behavior is to have neither of the web views go to sleep, obviously.

like image 555
ransomweaver Avatar asked Nov 30 '12 22:11

ransomweaver


2 Answers

JavaScript works in multiple UIWebViews but it depends on the JavaScript. Using JQuery or other external JavaScript code can be a problem in case you link it with a href. You can solve these issues by copying the code of all external JavaScript libraries into your web page HTML. This is the reason why simple JavaScript works fine. Example:

Screenshot of JavaScript in multiple web views

This is a UITableView with a UIWebView in every UITableViewCell. In webViewDidFinishLoad i do [webView stringByEvaluatingJavaScriptFromString:@"document.write('hey hallo'+new Date().getTime())"];

like image 83
MacMark Avatar answered Nov 15 '22 09:11

MacMark


Have you tried making one WebView the size of your 3 webViews and the using 3 iFrames inside that 1 UIWebView that load each javascript enabled page?

like image 41
Albert Renshaw Avatar answered Nov 15 '22 07:11

Albert Renshaw