head.js (720B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /** 8 * Loads an iframe. 9 * 10 * @return {Promise} promise that resolves when iframe is loaded. 11 */ 12 function createIframe(aSrcDoc) { 13 return new Promise(function (aResolve, aReject) { 14 let iframe = document.createElement("iframe"); 15 iframe.onload = function () { 16 aResolve(iframe.contentDocument); 17 }; 18 iframe.onerror = function () { 19 aReject("Failed to load iframe"); 20 }; 21 if (aSrcDoc) { 22 iframe.srcdoc = aSrcDoc; 23 } 24 document.body.appendChild(iframe); 25 }); 26 }