将脚本插入iFrame的标题,而不清除iFrame的主体

我正在寻找一个脚本添加到iFrame的标题,同时不会丢失iFrame的主体或标题中包含的所有内容……

这是我现在用新脚本更新iFrame的内容,但是它会清除iframe中的所有内容,而不是追加我想要的内容。 thxs! 乙

// Find the iFrame var iframe = document.getElementById('hi-world'); // create a string to use as a new document object var val = ''; // get a handle on the d document (in a cross-browser way) var doc = iframe.contentWindow || iframe.contentDocument; if (doc.document) { doc = doc.document;} // open, write content to, and close the document doc.open(); doc.write(val); doc.close(); 

 var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = 'yourpath'; headID.appendChild(newScript);