A few elements on a site im building take into account the size of the client. If the user decides to re size the window, some elements will look messed up. So, im trying to build a function that is constantly checking if any of dimensions change.
this is what ive made so far
<script>
var initial_width = document.body.offsetWidth,
initial_height = document.body.offsetHeight,
timer = window.setInterval(function () {checksize()}, 10);
function checksize () {
var current_width = document.body.offsetWidth,
current_height = document.body.offsetHeight;
if((initial_width != current_width) || (initial_height != current_height)){
location.reload();
}
else{
document.getElementById("test").innerHTML = "no change";
}
}
</script>
it does work, sometimes, but if the window is re sized beyond a certain point it just keeps refreshing.
Any suggestions on how to fix / improve this code? or should i take a different approach?
Cheers.