spec/helpers/dom-utils.js
function createIframeDocument ( iframe, documentStyles ) {
    if ( varExists( $ ) && iframe instanceof $ ) iframe = iframe[0];

    if ( ! iframe.ownerDocument.body.contains( iframe ) ) throw new Error( "The iframe has not been appended to the DOM, or is not a descendant of the body element. Can't create an iframe content document." );
    if ( ! iframe.contentDocument ) throw new Error( "Cannot access the iframe content document. Check for cross-domain policy restrictions." );

    documentStyles = documentStyles ? '<style type="text/css">\n' + documentStyles + '\n</style>\n' : "";
    iframe.contentDocument.write( '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<title></title>\n' + documentStyles + '</head>\n<body>\n</body>\n</html>' );

    return iframe.contentDocument;
}
function createIframeDocument ( iframe, documentStyles ) {
    if ( varExists( $ ) && iframe instanceof $ ) iframe = iframe[0];

    if ( ! iframe.ownerDocument.body.contains( iframe ) ) throw new Error( "The iframe has not been appended to the DOM, or is not a descendant of the body element. Can't create an iframe content document." );
    if ( ! iframe.contentDocument ) throw new Error( "Cannot access the iframe content document. Check for cross-domain policy restrictions." );

    documentStyles = documentStyles ? '<style type="text/css">\n' + documentStyles + '\n</style>\n' : "";
    iframe.contentDocument.write( '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<title></title>\n' + documentStyles + '</head>\n<body>\n</body>\n</html>' );

    return iframe.contentDocument;
}
function createIframeDocument ( iframe , documentStyles ) { if ( varExists ( $ ) && iframe instanceof $ ) iframe = iframe [ 0 ] ; if ( ! iframe . ownerDocument . body . contains ( iframe ) ) throw new Error ( "The iframe has not been appended to the DOM, or is not a descendant of the body element. Can't create an iframe content document." ) ; if ( ! iframe . contentDocument ) throw new Error ( "Cannot access the iframe content document. Check for cross-domain policy restrictions." ) ; documentStyles = documentStyles ? '<style type="text/css">\n' + documentStyles + '\n</style>\n' : "" ; iframe . contentDocument . write ( '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<title></title>\n' + documentStyles + '</head>\n<body>\n</body>\n</html>' ) ; return iframe . contentDocument ; }
Creates an iframe document with an HTML5 doctype and UTF-8 encoding.

The iframe element MUST have been appended to the DOM by the time this function is called, and it must be a
descendant of the body element. A document inside an iframe can only be created when these conditions are met.

@param   {HTMLIFrameElement|jQuery}  iframe
@param   {string}                    [documentStyles]  cssText string of CSS rules, styles the iframe document, e.g.
"html, body { overflow: hidden; } div.foo { margin: 2em; }"
@returns {Document}
Creates an iframe document with an HTML5 doctype and UTF - 8 encoding .