Android 浏览器orientationchange 事件不断触发

发布于 2024-09-30 03:40:07 字数 358 浏览 9 评论 0原文

以下是简单的 html,当您仅更改手机方向一次时,在 android 浏览器(nexus one)上查看时会导致连续的orientationchange事件链。

<html><body>
<script type="text/javascript">
window.addEventListener("orientationchange",function(){alert("test");},false);
</script>
</body></html>
Can somebody please explain and suggest some workaround?

Following is simple html, when viewed on android browser(nexus one) results into continuos orientationchange event chain when you change phone's orientation just once.

<html><body>
<script type="text/javascript">
window.addEventListener("orientationchange",function(){alert("test");},false);
</script>
</body></html>

Can somebody please explain and suggest some workaround?

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

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

发布评论

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

评论(3

给不了的爱 2024-10-07 03:40:07

orientationchange 被虚假触发:打开警报对话框或打开浏览器菜单会触发它,并且通常会触发多次。因此,打开警报菜单会导致事件循环,这意味着必须手动终止浏览器 - 它甚至缺乏针对警报循环的基本保护,并且导致菜单无法访问。

(我不明白任何生产浏览器都可以通过 while(1)alert(""); 删除。远程 JavaScript 代码从什么时候开始受到信任?这是最明显的客户端 DoS,并且这种情况总是在不经意间发生,但许多主流浏览器都没有注意到这一点。据我所知,Opera 是唯一能够正确处理该问题的浏览器,它使警报成为视口而不是浏览器本身的模式。)

orientationchange is fired spuriously: opening an alert dialog, or opening the browser menu fires it, and it often fires more than once. So, opening the alert menu causes an event loop, which means that the browser has to be killed manually--it lacks even basic protection against alert loops and it renders the menu inaccessible.

(I don't understand any production browser that can be taken out by while(1) alert("");. Since when is remote JavaScript code trusted? It's the most obvious client-DoS, and happens inadvertently all the time, yet many major browsers are oblivious to it. Opera is the only browser I know that handles it correctly, making alerts modal to the viewport and not the browser itself.)

我最亲爱的 2024-10-07 03:40:07

我认为法尔马里的意思是默认情况下会发生这种情况。您可以防止这种情况发生并侦听 Activity 中的配置更改,然后自行旋转屏幕,然后 Activity 就不会重新启动。请参阅有关旋转的系列

I think Falmarri means that by default that is what happens. You can prevent it from happening and listen for configuration changes in your activity, and then rotate the screen yourself, then the activity isn't restarted. See this series on rotation.

可爱咩 2024-10-07 03:40:07

这些设备似乎在调整窗口大小以反映新方向之前触发“orientationchange”事件。

如何解决此问题:github

These devices seem to trigger an 'orientationchange' event before the window is resized to reflect the new orientation.

How to fixed this: github

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