I've wrote a program that changes the page background on every click or key down.
question 1 - I have to give the body - height and width. it won't work without that. it is as if the body has no height at all. is there a way to get something like body=window?
question 2 - how can i get the actual window/screen size via javascript?
<style>
body {
background-color: yellow;
height: 800px;
width: 1400px;
}
</style>
<body onclick="myFunction()" onkeydown="myFunction()">
script
var news=0; // to check if new page load -> to go to full screen
function myFunction() {
// GO TO FULL SCREEN ON PAGE LOAD (OR REFRESH)
if (news==0) {
var elem = document.documentElement;
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
news = 1;
}
// give the body a new random color
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
document.body.style.backgroundColor = color;
}
</script>
</body>