How to open modal if the screen orientation is "Portrait" and hide the modal if he orientation is "Landscape"
This is my current script.
But this is not working if the page loads in portrait mode initially..
<script>
window.addEventListener("orientationchange", function() {
if(screen.availHeight > screen.availWidth){
$( '#oMsg' ).modal('show');
} else {
$( '#oMsg' ).modal('hide');
}
}, false);
</script>
UPDATE
So I've updated my code as follows now with the help of Nitin and Naveen
<script>
screen.orientation.addEventListener('change', function(e) {
scrFunction();
}, false);
</script>
<script>
function scrFunction() {
if(screen.availHeight > screen.availWidth){
$( '#oMsg' ).modal('show');
}
}
</script>
Also I changed my body
<body onload="scrFunction()">
But now my issues is even though it detects the orientation on page load, once I changed orientation back to Landscape, model remains there.. it's not removing..