Better alternative to multiple checks for typeof for nested dom object properties

Viewed 2444

I often find that to avoid undefined errors on dom stuff I have to do something like this:

if("undefined" != typeof parent 
    && "undefined" != typeof parent.main 
    && "undefined" != typeof parent.main.location){
// Act on a current iframe page from that page's parent location
}

Otherwise there's the potential to just get an undefined error when working with such heavily nested dom objects. Is there an easier way to check for these nested object properties without breaking everything?

1 Answers
Related