在本机iPhone应用程序中的UIWebView中使用InnerHTML是否存在错误? [英] Is there a bug with using InnerHTML inside a UIWebView within a native iPhone application?

查看:111
本文介绍了在本机iPhone应用程序中的UIWebView中使用InnerHTML是否存在错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当大的HTML / JS / CSS应用程序,当在iPhone上使用Safari作为Web应用程序运行时效果很好。

I have a fairly large HTML/JS/CSS application that works great when running as a web application with Safari on the iPhone.

在运行同一个应用程序时本机iPhone应用程序中的UIWebView在jQuery中调用以创建HTML片段以静默方式失败(即: $(< div> HELLO WORLD< / div>); 不会创建元素。

When running this same application in an UIWebView within a native iPhone application calls within jQuery to create HTML fragments fail silently (ie: $("<div>HELLO WORLD</div>"); will not create the element.

我在干净的jQuery方法中跟踪了以下等效代码片段:

I've tracked this down to the following equivalent code snippet in clean jQuery method:

var div = document.createElement(div);
div.innerHTML =< div> HELLO WORLD< / div>
;

当我查看 div.outerHTML 时,我看到
< div> /< ; div>

div.innerHTML 返回一个空字符串。

这似乎不是一个jQuery问题,也不会100%发生这种情况。我无法找到一个模式,但在某些情况下它可以工作2-一些,一些连续3次如果连续失败5-6次。这似乎只出现在Objective-C应用程序中的UIWebView中运行应用程序时。此外,我只在运行iOS 4.2的实际设备上看到了这个,而不是模拟器。

This does not appear to be a jQuery problem, nor does this happen 100% of the time. I haven’t been able to find a pattern, but in some cases it works 2-3 times in a row, sometimes if fails 5-6 times consecutively. This seems to only shows up when running the application inside a UIWebView in an Objective-C application. Also I’ve only seen this on an actual device running iOS 4.2, not the emulator.

有没有人碰到类似的东西?有没有人有修复?

Has anyone run into anything similar? Does anyone have a fix?

推荐答案

我也有这个问题。它发生在手机的CPU非常繁忙时(比如说100%)。然后渲染引擎有时会忘记innerHTML设置。

I had this problems too. It happens when the CPU of the phone is very busy (say 100%). Then the rendering engine sometimes forget about innerHTML settings.

我的统一项目是测试childNodes中是否有元素,否则再次应用它。

The solution included in my unify project is to test if there is an element in childNodes, otherwise apply it again.

var target = document.createElement("div");
var text = "<div>Hello World</div>";
target.innerHTML = text;
var self = this;
self.__intervalHandle = window.setInterval(function() {
  target.innerHTML = text:
  if (target.firstChild) {
    window.clearInterval(self.__intervalHandle);
    self.__intervalHandle = null;
  }
}, 100);

这会强制渲染引擎将innerHTML应用于DOM并为渲染引擎提供一些时间(100这个例子中的ms,在我们的测试中是一个很好的值来处理它。

This forces the rendering engine to apply the innerHTML to the DOM and gives the rendering engine some time (100 ms in this example, a good value in our tests) to handle it.

这篇关于在本机iPhone应用程序中的UIWebView中使用InnerHTML是否存在错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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