check if popup is open and popup.focus is defined before focusing