Cómo incluir un iframe en una etiqueta de script existente

Esto es posible si ha creado un iframe amigable. a continuación se muestra el código para crear un iframe amigable y escribir su contenido en él.

var createFriendlyiFrame = function (id, iframeContent, appendto) {
tratar {
var parentDiv = document.getElementById (appendto),
iframeElement = document.createElement (‘iframe’);
http://iframeElement.id = ‘iframe_’ + id;
iframeElement.src = “acerca de: en blanco”;
iframeElement.setAttribute (‘desplazamiento’, ‘no’);
iframeElement.width = ‘0px’;
iframeElement.height = ‘0px’;
iframeElement.style.display = “none”;
parentDiv.appendChild (iframeElement);
var content = ” + ‘ ‘ + iframeContent + ‘ ‘;
var doc = iframeElement.contentDocument || iframeElement.contentWindow.document;
doc.open (‘text / html’, ‘replace’);
doc.write (contenido);
doc.close ();
} captura (e) {
console.error (e);
}
}

llamar a la función anterior con parámetros

var iframecontent = ‘ function Loadtitles () {var xhttp = new XMLHttpRequest (); xhttp.onreadystatechange = function () {if (this.readyState == 4 && this.status == 200) {}}} ‘;
createFriendlyiFrame (“iframeid”, iframecontent, “appendtoelementid”);

Solo es posible si la página de origen del iframe y su página base pertenecen al mismo servidor. de lo contrario, arrojará un error, algo como el acceso cruzado al sitio de origen falló

if (! $ (‘head> script [src = “js / customFunction.js”]’). length) {
$ (‘iframe # yourId head’). append ($ (‘').attr('src','js/customFunction.js'));
}