iOS 6多个UIWebViews:Javascript只在一个中运行 [英] iOS 6 multiple UIWebViews: Javascript only runs in one

查看:82
本文介绍了iOS 6多个UIWebViews:Javascript只在一个中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 6 iPad应用程序在两个UIWebView中显示内容。如果两个Web视图都包含jquery图像旋转器,则一次只能运行一个。正在运行< iOS 6,都能正常运行。

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.

如果重新加载非动画webview的内容,它将开始工作,而另一个停止。此外,仅在模拟器中,我有时可以通过单击/拖动来启动已停止的Web视图(以及另一个停止)。

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.

如果其中一个Web视图中没有javascript,则重新加载已停止的Web视图不会停止另一个的运行。

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.

我首先想到的是这是一个焦点问题,但最后一点似乎反驳了这一点,并指出两种网络观点之间存在某种污染。两个旋转器具有相同的选择器和相同的js脚本,但js文件在本地缓存并且被唯一地重命名以消除缓存过程中的任何踩踏。

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.

我在iOS 6发行说明中找不到任何描述不同UIWebView之间焦点变化的内容。

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

Web视图位于XIB中,但不是同一父UIView的兄弟。

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.

推荐答案

JavaScript可以在多个UIWebView中运行,但它依赖于JavaScript。使用JQuery或其他外部JavaScript代码可能会出现问题,以防您将其与href链接。您可以通过将所有外部JavaScript库的代码复制到网页HTML中来解决这些问题。这就是为什么简单的JavaScript工作正常的原因。示例:

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:

这是一个UITableView,每个UITableViewCell都有一个UIWebView。在webViewDidFinishLoad中我做 [webView stringByEvaluatingJavaScriptFromString:@document.write('hey hallo'+ new Date()。getTime())];

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

这篇关于iOS 6多个UIWebViews:Javascript只在一个中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆