Sunday 13 April 2014

Problem #6: iframe.contentDocument is null

Normally to access the contents of an iframe you've created you use iframe.contentDocument. However, sometimes it turns up null, even if there are clearly elements within the iframe. This is because of the Same-origin policy. In a nutshell, you're not allowed to access the contents of the iframe through js if it's from a different origin.

I feel that an more explicit warning would have saved me a lot of time. Although this is a fair policy, it's not always at the top of my mind while writing code.