Check that document.popupNode exists before using

Squash frequent console errors:
"TypeError: document.popupNode is null"