var oldWidth = window.innerWidth; window.onresize = function () { var newWidth = window.innerWidth; if (newWidth != oldWidth) { alert("width changed"); oldWidth = newWidth; } };