Android Browser orientationchange event keeps firing

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?

Answers:

Answer

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.)

Answer

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.

Answer

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

How to fixed this: github

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.