Document beforeOpen event