Search code examples
javascriptandroidscreen-orientationsamsung-mobile

Javascript: Changing properties if screen is turned do not work on Samsung. Ideas how to fix that?


Ho Guys i have this little code which changes my width if i rotate my phone.

window.addEventListener("orientationchange", function() {

  if (window.matchMedia("(orientation: portrait)").matches) {

document.getElementById("iframe-startpage-mobile").style.width ="90%";
document.getElementById("iframe-startpage-mobile").style.marginLeft ="5%";
    } else {
        document.getElementById("iframe-startpage-mobile").style.width ="100%";
        document.getElementById("iframe-startpage-mobile").style.marginLeft ="0%";
    }

  }, false);

It works perfect on my Android Xiaomi Redmi Note 4 (works in chrome and firefox) but it dosn´t work on my Samsung Galaxy S8 ( not chrome or samsung browser). Any idea how i can fix that?


Solution

  • i use wordpress and on my samsung galaxy in landscape mode wordpress ( i use the avada fusion template ) think that the galaxy screen is an medium screen. So i just toggle the container on medium screen too and now it works :) The Problem was my galaxy showed me the container for dekstop which has another id so i thaught my nothing happend but this was wrong it just dosn´t happend on my mobile-container. I simply changed #iframe-startpage-mobile to #iframe-startpage evethings fixed. Thx for the attention :D