Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload the webpage when orientation changes?

I'm trying to trigger an event with jQuery mobile that automatically reloads the page when the device's orientation changes. I have media queries written with max-device-width, orientation:landscape, and orientation: portrait. Since the <video> wont scale properly...the only solution I can think of is to refresh the page to the correct media query with the device is rotated.

How do I go about doing this? Thanks.

like image 426
David Berning Avatar asked Jul 17 '13 19:07

David Berning


People also ask

How do you prevent the data from reloading and resetting when the screen is rotated?

Prevent Activity to recreated Most common solution to dealing with orientation changes by setting the android:configChanges flag on your Activity in AndroidManifest. xml. Using this attribute your Activities won't be recreated and all your views and data will still be there after orientation change. Save this answer.


2 Answers

Thanks guys who answered but I found this and used this and it worked perfectly.

<script type="text/javascript"> // RELOADS WEBPAGE WHEN MOBILE ORIENTATION CHANGES  
    window.onorientationchange = function() { 
        var orientation = window.orientation; 
            switch(orientation) { 
                case 0:
                case 90:
                case -90: window.location.reload(); 
                break; } 
    };

like image 80
David Berning Avatar answered Sep 18 '22 03:09

David Berning


How about this?

$(window).on('orientationchange', function(e) {
     $.mobile.changePage(window.location.href, {
        allowSamePageTransition: true,
        transition: 'none',
        reloadPage: true
    });
});

It would be best to namespace that orientationchange event to a specific page.

jQM docs on orientationchange event

like image 24
Ross Avatar answered Sep 22 '22 03:09

Ross