how to execute javascript cde on window rotate

JavaScript
window.addEventListener("orientationchange", function(event) {
  console.log("the orientation of the device is now " + event.target.screen.orientation.angle);
});

Source

Also in JavaScript: