诺基亚的 jQuery 文档准备有问题? (警报修复了诺基亚中的 jQuery。建议替代方案吗?)

发布于 2024-11-26 12:15:51 字数 1346 浏览 2 评论 0原文

我在移动网站上运行了一些 jQuery,它执行一些布局计算并调整一些元素的大小。

这在我们支持的浏览器(甚至是诺基亚的浏览器)上运行良好,但随后我收到了有关诺基亚上存在问题的报告。

然后我意识到我的 E72 的系统软件上次更新是在去年年底,所以我继续下载了最新版本。而且,现在错误就在那里。

在完成向函数添加警报的常规 JS 调试过程后,我发现如果我在执行所有布局计算和调整大小的函数中触发警报,那么它就可以工作了!如果我忽略警报,则什么也不会发生。

过去,我在 IE 中有时会发生类似的情况,无论出于何种原因,IE 需要让 JS“暂停”才能赶上。通常的技巧是使用将我遇到问题的函数包装在设置为 0 的 setTimeout 中。

我在诺基亚上尝试过此操作,但没有成功。然后我尝试了1秒、10秒,但仍然没有成功。只有发出警报才能使其发挥作用。

关于这一点有什么理论吗? JS 警报在计时 JS 函数方面是否有一些功能可以通过警报或 setTimeout 之外的其他功能来复制?

更新:

根据请求,示例代码。这是从文档就绪触发的函数内部。

var extraWidths = $icon.width() + $button.width() + 20 + 5; 
var containerWidth = $panel.width();
var percentWidth = 100 - ( Math.floor((extraWidths/containerWidth)*100) );
$searchInput.css('width',percentWidth+'%');
alert('hello world'); // if I add this, Nokia works correctly. 

我正在做的是,在文档渲染之后,我计算一些元素的宽度,从父容器的总宽度中减去该宽度,然后调整其中的输入字段以占用剩余空间(设置为百分比宽度)。

这在 Webkit、Firefox、BlackBerry(OS5 和 OS6)中运行良好,所以我不认为这是代码错误,但希望有人找到了解决方法(除了警报)。

更新 2:

经过更多研究,我有了一个新理论:诺基亚网络浏览器没有正确通知 jQuery 文件已准备好。

我发现,只有当我将需要计算 DOM 元素尺寸的 jQuery 包装在 setTimeout 中时,包装 jQuery 才有效。而且这不是任意的时间延迟...我需要确保时间延迟比浏览器正确渲染 DOM 所需的时间更长。因为我不可能知道给定的设备速度和网络速度,所以我必须坚持 1-2 秒的时间,这不会减少它。

所以,我的新问题是:有人知道 jQuery 的文档就绪有任何问题并且它在诺基亚设备上无法正常工作吗?如果是这样,那么不幸的是,我们需要重新考虑 jQuery 的使用。

I have some jQuery running on a mobile web site that does some layout calculations and resizes a few elements.

This was working fine on the browsers we support--even Nokia's--but I then received reports that there were problems on the Nokia.

I then realized that my E72's System software was last updated late last year so went ahead and downloaded the newest version. And, now the bug is there.

After going through the usual JS debug process of adding alerts to the function, I found that if I trigger an alert in the function that's doing all the layout calculations and resizing, then it works! If I omit the alert, nothing happens.

In the past I've had something similar to this happen in IE on occasion, where IE, for whatever reason, needed to have the JS 'pause' for it to catch up. The usual trick was to use wrap the function(s) that I was having trouble with in a setTimeout set to 0.

I tried this on the Nokia, but no luck. I then tried 1 second, 10 seconds, but still, no luck. Only an alert would get it to work.

Any theories on this one? Is there something that a JS alert does in terms of timing JS functions that could potentially be replicated with something other than an alert or setTimeout?

UPDATE:

Per request, the sample code. This is inside a function that it triggered from document ready.

var extraWidths = $icon.width() + $button.width() + 20 + 5; 
var containerWidth = $panel.width();
var percentWidth = 100 - ( Math.floor((extraWidths/containerWidth)*100) );
$searchInput.css('width',percentWidth+'%');
alert('hello world'); // if I add this, Nokia works correctly. 

What I'm doing is that after the document renders, I'm calculating the widths of some elements, subtracting that from the total width of the parent container, then adjusting an input field inside of it to take up the remaining space (set to a percentage width).

This works fine in Webkit, Firefox, BlackBerry (OS5 and OS6) so I don't think it's a code error, but hoping that someone has come across a workaround (aside from the alert).

UPDATE 2:

After more research, I have a new theory: Nokia web browser doesn't properly notivy jQuery that the document is ready.

I've found that wrapping jQuery that needs to calculate dimensions of DOM elements only works when I wrap it inside a setTimeout. And it's not an arbitrary time delay...I need to make sure the time delay is LONGER than the time it takes the browser to render the DOM properly. Since I can't possibly know that given device speeds and network speeds, I have to stick in times of 1-2 seconds, which isn't going to cut it.

So, my new question: Is anyone aware of any issue's with jQuery's document ready and it not working properly on Nokia devices? If so, then we need to rethink our use of jQuery, unfortunately.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮湿 2024-12-03 12:15:51

不要将 $(document).ready(function() 添加到正文中,而是使用 $(document.getElementById('bourbodyid')).ready(function()代码> 。

也许与其他方法相比,解决方法并没有那么错误。

Instead of $(document).ready(function() add an id to your body, and use $(document.getElementById('bourbodyid')).ready(function() .

Maybe not so wrong of a workaround than the other ones.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文