How to do Reload a web page when a user turns a mobile into an album

I am making a web application for Android and iPhone. My problem is that I want to refresh the web page when the user navigates to the landscape. Since I'm new to javascript, I don't know how to do this. Please help me

+6
source share
2 answers

You can use changechange jQuery Mobile and then do

window.location.reload(); 

to refresh the page.

For instance:

 $(function(){ // Set Inital orientation // get the initial orientation from window which // returns 0 for portrait and 1 for landscape if(window.orientation == 0){ var ori = "portrait"; }else{ var ori = "landscape"; } changeOrientation(ori); // Orientation Change // When orientation changes event is triggered // exposing an orientation property of either // landscape or portrait $('body').bind('orientationchange',function(event){ changeOrientation(event.orientation) }) // Change the style dependengt on orientation function changeOrientation(ori){ // Remove all classes separated by spaces $("#orientation").removeClass('portrait landscape'); $("#orientation").addClass(ori); $("#orientation").html("<p>"+ori.toUpperCase()+"</p>"); } }); 
+5
source

You can use a timer and periodically check:

 if (window.innerHeight > window.innerWidth) { // Redirect code, window.location... } 
0
source

Source: https://habr.com/ru/post/905897/


All Articles