medialize/ally.js

View on GitHub
src/util/get-content-document.js

Summary

Maintainability
A
1 hr
Test Coverage

export default function(node) {
  try {
    // works on <object> and <iframe>
    return node.contentDocument
      // works on <object> and <iframe>
      || node.contentWindow && node.contentWindow.document
      // works on <object> and <iframe> that contain SVG
      || node.getSVGDocument && node.getSVGDocument()
      || null;
  } catch (e) {
    // SecurityError: Failed to read the 'contentDocument' property from 'HTMLObjectElement'
    // also IE may throw member not found exception e.g. on <object type="image/png">
    return null;
  }
}