Why doesn't this "if" statement redirect the page?

I am using the following html code at the startup of my Android wallpaper app to branch off to different home screens based on the screen size. When I try it on my large screen Android device, it stays on the same page (it freezes on this page’s blue background) and doesn’t redirect. Can you look it over and see what might be wrong?

<!DOCTYPE html>
<html lang="en">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no" name="viewport">
	<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
	<script type="text/javascript" charset="utf-8">
        document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {

		if (screen.width > 640) {
			window.location = "ipad/index.html";
		else {
			window.location = "iphone/index.html";

	<style type="text/css">
		body { background-color: blue; }

Given that it seems to work on some Android devices and not on the large screen one, it would help if we knew what particular large screen Android device that this is.

I am using a 2012 Asus Nexus 7 device. This is the only device I’m testing on. Thanks!

Thanks - that seems to be a known issue for it on 4.2.

Some good solutions seem to be available from this google groups thread: https://groups.google.com/forum/#!msg/phonegap/MDYdSSE9ALA/ShS0hNiTJFIJ
Including, changing the target version from 17 down to 16.

Thank you! I am no longer getting the freezing, but the home page is coming on correctly. Also, a change to the code above is:

window.location.href = etc.

Now what is happening is when I test the connection script to inform the person that a download isn’t possible because there’s no connection, the app stops during the splashscreen with “Unfortunately [app name] has stopped.”

Back to the drawing board!