Screen.width Not Checking For A Window Resize
I'm currently using this script to see if a user that's visiting my site has a screen width smaller than 800. The problem I have is that I also want the alert to be triggered when
Solution 1:
Wrap it in a resize event and you need to get the window's width, not the screen's width
window.addEventListener("resize", function() {
if (window.innerWidth <= 800) {
window.alert("screen smaller than 800");
}
})
Solution 2:
You need:
window.addEventListener('resize', function() {
if (window.innerWidth <= 800) {
window.alert("screen smaller than 800");
}
}, true);
Post a Comment for "Screen.width Not Checking For A Window Resize"