Bug fix for error in Javascript when iframe is hidden