function getScrollbarWidth(){ var iDiv = new Element('div'); iDiv.setStyle({height:'100px'}); var oDiv = new Element('div'); oDiv.setStyle({width:'50px',height:'50px',overflow:'hidden',position:'absolute',top:'200px',left:'200px'}) document.body.insert({top:oDiv}); oDiv.insert({top:iDiv}); var w1 = iDiv.getWidth(); oDiv.setStyle({overflow:'auto'}); var w2 = iDiv.getWidth(); oDiv.remove(); return (w1 - w2); }
I used prototype. The jquery verison is here:http://jdsharp.us/jQuery/minute/calculate-scrollbar-width.php
I just dont know if its totally crossbrowser.