var getdiv=document.getelementbyid('returntop'); getdiv.onclick=function(){ window.scrollto(0,0); } window.onscroll=function(){ if(document.documentelement.scrolltop){ getdiv.style.display="block"; }else if(document.body.scrolltop){ getdiv.style.display="block"; }else{ getdiv.style.display="block"; } } function getwinsize(){ var winheight=window.innerheight,winwidth=window.innerwidth; if(document.documentelement.clientheight){ winheight=document.documentelement.clientheight; winwidth=document.documentelement.clientwidth; }else{ winheight=document.body.clientheight; winwidth=document.body.clientwidth; } var height=winheight-50; var width=winwidth-100; getdiv.style.top=height+"px"; getdiv.style.left=width+"px"; } getwinsize(); window.onresize=getwinsize;