function fun(){
var wWidth = null,
wHeight = null;
if(window.innerHeight && window.innerWidth){
wHeight = window.innerHeight;
wWidth = window.innerWidth;
}else if((document.body) && (document.body.clientHeight) && (document.body.clientWidth)){
wWidth = window.clientWidth;
wHeight = window.clientHeight;
}
var boxWidth = document.getElementById("box").clientWidth;
var boxHeight = document.getElementById("box").clientHeight;
box.style.marginLeft = (wWidth - boxWidth)/2 + "px";
box.style.marginTop = (wHeight - boxHeight)/2 + "px";
}
window.onload = window.onresize = function(){fun()}