【发布时间】:2011-02-09 01:28:24
【问题描述】:
我希望将脚本添加到 iFrame 的标头,同时不会丢失 iFrame 的正文或标头中包含的所有内容...
这就是我现在所拥有的,它确实使用新脚本更新了 iFrame,但它清除了 iframe 中的所有内容,而不是我想要的附加内容。谢谢!乙
// Find the iFrame
var iframe = document.getElementById('hi-world');
// create a string to use as a new document object
var val = '<scr' + 'ipt type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></scr' + 'ipt>';
// get a handle on the <iframe>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();
【问题讨论】:
标签: javascript jquery dom iframe window