Monthly Archives: July 2016

Google Chrome – Uncaught Security Error: Failed to read the ‘contentDocument’ property from ‘HTMLIFrameElement’

by ,

When trying to access an iframe element’s window and document properties from a parent page in Google Chrome, you may get the following Uncaught Security Error in the Developer Tools Console:

Uncaught SecurityError when accessing iframe element

This happens because all of the modern browsers, except Chrome support both the iframereference.contentWindow and iframereference.contentDocument properities, only if the iframe is on the same domain as the parent page containing the frame. To include Chrome use the following JavaScript code:


var content = iframe1.contentDocument || iframe1.contentWindow.document; var elementID = content.getElementById('elementInsideIFrame');

If you open the parent document file locally in Chrome without using a web server, the code above will not work. This is a great piece of code to use when you want toggle a window or iframe to expand such as in an animated banner.