Id use an If statement on any page it can appear: If(pop is visible) { close popup(); } else{ }