SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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?

    HTML Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <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"; 
    		}
    } 
    	</script>
    
    	<style type="text/css">
    		body { background-color: blue; }
    	</style>
    </head>
    <body>
    </body>
    </html>
    Steve Husting

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StevenHu View Post
    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.
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I am using a 2012 Asus Nexus 7 device. This is the only device I'm testing on. Thanks!
    Steve Husting

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StevenHu View Post
    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.
    http://stackoverflow.com/questions/1...d-4-2/13455618

    Some good solutions seem to be available from this google groups thread: https://groups.google.com/forum/#!ms...A/ShS0hNiTJFIJ
    Including, changing the target version from 17 down to 16.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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!
    Steve Husting


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •