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?
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?
Share
Improve this question
asked Oct 28, 2010 at 17:08
bhupsbhups
14.9k8 gold badges52 silver badges57 bronze badges
2
- Orientation change reloads the activity. It's reloading the page every time the orientation changes. – Falmarri Commented Oct 28, 2010 at 17:59
- Then what is the point of having an orientationchange event? Isn't is useless? – bhups Commented Oct 28, 2010 at 18:01
3 Answers
Reset to default 4orientationchange 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.)
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.
These devices seem to trigger an 'orientationchange' event before the window is resized to reflect the new orientation.
How to fixed this: github