I got around it by having the code below test if it was a 'modal' box or not with an arbitrary ID that was only in the 'modal' window:
var element = document.getElementById('system-message-container');
if (typeof(element) != 'undefined' && element != null)
{
document.getElementById('cartarea').style.display='none';
}