diff --git a/src/js/video.js b/src/js/video.js index d1a7abfc4..928856de5 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -4,7 +4,6 @@ */ import {version} from '../../package.json'; import window from 'global/window'; -import document from 'global/document'; import * as setup from './setup'; import * as stylesheet from './utils/stylesheet.js'; import Component from './component'; @@ -143,7 +142,13 @@ function videojs(id, options, ready) { throw new TypeError('The element or ID supplied is not valid. (videojs)'); } - if (!document.body.contains(el)) { + // document.contains(el) will only check if el is contained within that one document. + // This causes problems for elements in iframes. + // Instead, use the element's ownerDocument instead of the global document. + // This will make sure that the element is indeed in the dom of that document. + // Additionally, check that the document in question has a default view. + // If the document is no longer attached to the dom, the defaultView of the document will be null. + if (!el.ownerDocument.defaultView || !el.ownerDocument.contains(el)) { log.warn('The element supplied is not included in the DOM'); }