Sometimes when displaying popups I want to remove scrolling from the body (setting it's overflow to hidden) the problem with this is that depending on the browser and OS it might or might not have a permanent scrollbar (like newest versions of IOS and Ubuntu have a scrollbar that toggles on hover).
So when I do:
$('body').css('overflow','hidden');
The content may move X px to the right, since the scrollbar was taking space from the viewport. To fix this I thought about doing this:
var width = $(window).width();
$('body').css('overflow','hidden');
var margin = $(window).width() - width;
$('html').css('margin-right',margin);
Which seems to work fine as it adds a white bar at the right of the same width of the scrollbar, however this doesn't work if there are fixed elements on the page (which will move right when the scrollbar is removed).
How can I maintain all the contents position, while removing the scrollbar?