0

JavaScript code 

function checkScreen(){


  const checkMobile = window.matchMedia('screen and (max-width: 575px)');
  const checkTablet = window.matchMedia('screen and (min-width: 576px) and (max-width: 991px)');
  const checkDesktop = window.matchMedia('screen and (min-width: 992px)');

  checkMobile.addListener(function(evt){

    if(evt.matches) {

      
        alert("Mobile")

    }
  });

  checkTablet.addListener(function(evt){

    if(evt.matches) {

      
        alert("Tabletty")



    }
  });

 checkDesktop.addListener(function(evt){

    if(evt.matches) {

   
        alert("desktoppy")

    }
  });

  
  
}

checkScreen()

The alert for each view port is not triggere when the page is loaded. the viewport only triggered when the page is manually resized. i am looking for a way to triggered the code when the page load for each viewport. thanks

Kiki-ko
  • 1
  • 5

0 Answers0