One option (and the easiest option) to do what you want would be to use an "input parameter" (IsPopup) then you wouldn't need to use that piece of javascript code that i' have mention above, instead you would hide the header/footer with an "if" widget (IsPopup)

You would also be able to use the "IsPopup" input parameter/variable to perform the required task as you have described, since IsPopup is a local variable.