use document instead of window