Fixed bug in Javascript when redirecting browser