box-ui-elements-mlh
Version:
50 lines (42 loc) • 1.12 kB
JavaScript
/**
*
* @file Function to create iframe and downloading
* @author Box
*/
/**
* Creates an empty iframe or uses an existing one
* for the purposes of downloading or printing
*
* @private
* @return {HTMLIFrameElement} Iframe
*/
function createDownloadIframe() {
var iframe = document.querySelector('#boxdownloadiframe');
if (!iframe) {
// if no existing iframe create a new one
iframe = document.createElement('iframe');
iframe.setAttribute('id', 'boxdownloadiframe');
iframe.style.display = 'none';
if (document.body) {
document.body.appendChild(iframe);
}
} // If the iframe previously failed to load contentDocument will be null
if (iframe.contentDocument) {
// Clean the iframe up
iframe.contentDocument.write('<head></head><body></body>');
}
return iframe;
}
/**
* Opens url in an iframe
* Used for downloads
*
* @param {string} url - URL to open
* @return {HTMLIFrameElement}
*/
export default function openUrlInsideIframe(url) {
var iframe = createDownloadIframe();
iframe.src = url;
return iframe;
}
//# sourceMappingURL=iframe.js.map