Detect vertical scroll and scrollbar width and apply width change to body
<p>In my page, I wish to detect whether the page has vertical scrollbars, and if so, need to detect the width of the scrollbar, so I can reduce my body by the width and thus prevent my sidebar from changing location from viewing a non-scrolling page to a scrolling page.
I have the following jQuery/Javascript code:</p>

<pre><code>        $(document).ready(function () {
        var parent, child, width;

        if (width === undefined) {
            parent = $('&lt;div style="width:50px;height:50px;overflow:auto"&gt;&lt;div/&gt;&lt;/div&gt;').appendTo('body');
            child = parent.children();
            width = child.innerWidth() - child.height(99).innerWidth();
            parent.remove();
        }

        if ($("body").height() &gt; $(window).height()) {
            //change width of body here
        }
    });
</code></pre>

<p>Unfortunately, this code doesn't work for me. Can someone please let me know where I'm going wrong?</p>
